【发布时间】:2018-06-28 08:01:53
【问题描述】:
我正在尝试根据 item._id 更改标题。我存储在组件中的项目。 这是我的 html
<h1 mat-dialog-title>{{item._id ? "Update" : "Add"}} animal</h1>
下面是我的 dialog-overview-example.ts
import {Component, Inject} from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
/**
* @title Dialog Overview
*/
@Component({
selector: 'dialog-overview-example',
templateUrl: 'dialog-overview-example.html',
styleUrls: ['dialog-overview-example.css'],
})
export class DialogOverviewExample {
animal: string;
name: string;
item:string;
constructor(public dialog: MatDialog) {}
openDialog(): void {
item =[{"_id": "2","animal":"lion","weiht":"100"}];
let dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: { name: this.name, animal: this.animal,item: this.item }
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
}
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog {
constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
onNoClick(): void {
this.dialogRef.close();
}
}
如果 _id 存在于项目标题中,则应显示更新动物,否则应显示在我们的案例中添加动物 id 已存在于项目中,因此应显示更新动物..帮帮我
【问题讨论】:
标签: javascript angularjs angular2-forms angular5