我有一个MatDialog,它不显示正在传递给它的数据。为什么last_name字段正确填充,但companyDropdown没有填充? onSubscribe的控制台输出将按预期方式触发-触发后视图不会更新。
HTML
<h4>Last Name:</h4>
<mat-form-field>
<input placeholder="Last name:" [(ngModel)]="data.last_name">
</mat-form-field>
<h4>Company: {{data|json}}</h4>
<mat-form-field>
<mat-select [(ngModel)]="data.company_id">
<mat-option *ngFor="let s of data.companyDropdown" [value]="s.id">{{s}}</mat-option>
</mat-select>
</mat-form-field>
TS
export class UserEditDialogComponent implements OnInit{
constructor(public dialogRef: MatDialogRef<UserEditDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: ArgosUserModel,
private svc: GreencardService) {
}
ngOnInit() {
console.log('dialog on init()')
this.data.lgid = 1;//TEMP. need to pass from c#
this.svc.getCompanies(this.data.lgid.toString()).
subscribe(x => { this.data.companyDropdown = x; console.log('dialog with dropdown: ' + JSON.stringify(this.data.companyDropdown)) })
}
答案 0 :(得分:0)
这对我有用。首先尝试使用小型静态数组/对象。它应该工作。 还不应该将您的s {{s}}的插值不像{{s.property}}一样?
<mat-form-field>
<mat-select [(ngModel)]="data.optionselected">
<mat-option *ngFor="let option of data.options" [value]="option.id">{{option.name}}</mat-option>
</mat-select>
</mat-form-field>