angular使用经验(1)

angular是以component(组件)为架构的前端框架。angular页面的最终展示是以组件为基础,基本上每个页面都是由组件构成。

阅读组件的步骤
步骤一

阅读==.html==文件,找出里面绑定的数据。

步骤二

在.component.ts文件中去找对应的数据获取的方法和方式。从而滤清代码的逻辑。

Angular使用 dialog 可以通过 Angular Material 提供的 MatDialog 实现。 首先,需要在应用中引入 Angular Material 模块。在 app.module.ts 中导入以下模块: ``` import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MatInputModule } from '@angular/material/input'; import { MatButtonModule } from '@angular/material/button'; import { MatDialogModule } from '@angular/material/dialog'; @NgModule({ imports: [ BrowserAnimationsModule, FormsModule, ReactiveFormsModule, MatInputModule, MatButtonModule, MatDialogModule ], exports: [ BrowserAnimationsModule, FormsModule, ReactiveFormsModule, MatInputModule, MatButtonModule, MatDialogModule ] }) export class MaterialModule {} ``` 然后,在组件中使用 MatDialog 打开一个对话框: ``` import { Component, Inject } from '@angular/core'; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; @Component({ selector: 'app-example-dialog', template: ` <h2 mat-dialog-title>{{ data.title }}</h2> <mat-dialog-content> <p>{{ data.content }}</p> </mat-dialog-content> <mat-dialog-actions> <button mat-button mat-dialog-close>取消</button> <button mat-button [mat-dialog-close]="true" cdkFocusInitial>确定</button> </mat-dialog-actions> ` }) export class ExampleDialogComponent { constructor( public dialogRef: MatDialogRef<ExampleDialogComponent>, @Inject(MAT_DIALOG_DATA) public data: any ) {} } @Component({ selector: 'app-example', template: ` <button mat-button (click)="openDialog()">打开对话框</button> ` }) export class ExampleComponent { constructor(public dialog: MatDialog) {} openDialog() { const dialogRef = this.dialog.open(ExampleDialogComponent, { width: '300px', data: { title: '提示', content: '确认删除?' } }); dialogRef.afterClosed().subscribe(result => { if (result) { console.log('删除'); } }); } } ``` 在 ExampleDialogComponent 中定义对话框的内容,并通过 MatDialogRef 关闭对话框。在 ExampleComponent 中通过 dialog.open() 打开对话框,并监听对话框关闭事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值