MatDialog不显示通过subscribe更新的值

问题描述 投票:0回答:1

我有一个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)) })
}
angular angular-material subscribe
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.