我有这个组件:
export class RequestedProductList implements DoCheck {
@Input() requests: Request[] = [];
differ: any;
constructor(
private globalVariablesService: GlobalVariablesService,
private route: ActivatedRoute,
private requestService: RequestService,
private loaderService: LoaderService,
private collectionService: CollectionService,
private accountService: AccountService,
private differs: IterableDiffers
) {
this.requests = requestService.requests;
this.differ = differs.find([]).create(null);
this.route.params.subscribe(
params => this.accountId = params["id"]
);
this.loadRequests();
this.loadAccountData();
}
ngDoCheck() {
const change = this.differ.diff(this.requests);
console.log(change);
}
请求数组显示在模板中,并且有一些像这样的双向绑定表单字段。
<td><input class="form-control form-control-sm comment" [(ngModel)]="request.comment" type="text" placeholder=".form-control-sm"></td>
当我输入数据时,此表单字段为ngDoCheck()运行但更改始终为空。
我试图获取数组中已更改的对象,以便我可以在数据库中更新它。为什么差异没有检测到变化?