Angular Material的MatDialog.open(Component)自动选择Component的第一个链接。
创始人
2024-10-19 23:00:38
0

要实现Angular Material的MatDialog.open(Component)自动选择Component的第一个链接,可以按照以下方法进行操作:

  1. 首先,在你的Component中创建一个成员变量来存储链接列表的数组,以及一个用于存储当前选择的链接的变量。例如:
import { Component } from '@angular/core';

@Component({
  selector: 'app-dialog-component',
  template: `
    

Links:

  • {{ link }}
`, styles: [` .selected { font-weight: bold; } `] }) export class DialogComponent { links = ['Link 1', 'Link 2', 'Link 3']; selectedLink: string; selectLink(link: string) { this.selectedLink = link; } }
  1. 在你的父组件中使用MatDialog.open方法打开对话框,并将DialogComponent作为参数传递进去。例如:
import { Component } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { DialogComponent } from './dialog.component';

@Component({
  selector: 'app-parent-component',
  template: `
    
  `
})
export class ParentComponent {
  constructor(private dialog: MatDialog) {}

  openDialog() {
    const dialogRef = this.dialog.open(DialogComponent);
  }
}
  1. 在DialogComponent的构造函数中注入MatDialogRef来获取对话框的引用,并在对话框打开时自动选择第一个链接。例如:
import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';

@Component({
  selector: 'app-dialog-component',
  template: `
    

Links:

  • {{ link }}
`, styles: [` .selected { font-weight: bold; } `] }) export class DialogComponent implements OnInit { links = ['Link 1', 'Link 2', 'Link 3']; selectedLink: string; constructor(private dialogRef: MatDialogRef) {} ngOnInit() { this.selectedLink = this.links[0]; } selectLink(link: string) { this.selectedLink = link; } }

现在,当你打开对话框时,它应该会自动选择第一个链接。你可以通过选择不同的链接来更改当前选择的链接。

相关内容

热门资讯

透视练习!德普之星透视辅助软件... 透视练习!德普之星透视辅助软件激活码,德州透视是真的假的(透视)真是真的有挂(哔哩哔哩)1、很好的工...
透视妙计!德普之星透视软件免费... 透视妙计!德普之星透视软件免费入口官网,如何下载德普之星辅助软件(透视)本来真的有脚本方法(哔哩哔哩...
透视窍门!wepoker公共底... 透视窍门!wepoker公共底牌,wepoker免费透视脚本(透视)一直真的是有挂(哔哩哔哩)1、w...
透视总结!wpk插件辅助,wp... 透视总结!wpk插件辅助,wpk系统是否存在作必弊行为(透视)一贯有脚本app(哔哩哔哩)1、用户打...
透视讲义!约局吧德州透视,aa... 透视讲义!约局吧德州透视,aapoker能控制牌吗(透视)一直真的有挂(哔哩哔哩);1、上手简单,内...
透视要领!hhpoker可以控... 透视要领!hhpoker可以控制吗,hhpoker怎么破解(透视)好像存在有透视脚本(哔哩哔哩)1、...
透视资料!wepoker透视破... 透视资料!wepoker透视破解版,wepoker脚本下载(透视)一直是真的挂(哔哩哔哩)1、超多福...
透视举措!wepoker有脚本... 透视举措!wepoker有脚本吗,哈糖大菠萝开挂(透视)一贯是真的挂(哔哩哔哩)1、下载好哈糖大菠萝...
透视手筋!wepoker-h5... 透视手筋!wepoker-h5下载,wepoker有辅助工具吗(透视)一贯有脚本软件(哔哩哔哩)1、...
透视指南!aapoker怎么控... 透视指南!aapoker怎么控制牌,wpk插件(透视)都是真的有挂(哔哩哔哩)1、完成aapoker...