在我的应用程序中,我有一个组件,其中有一个方法可以从另一个组件的输入调用,此方法更新应该反映在模型中的ngFor中的模型,但是没有观察到任何更改。
以下是我app.component.html的一个片段:
<app-schedule #scheduleReference [candidates]="candidatesReference"></app-schedule>
<app-candidates #candidatesReference></app-candidates>
在schedule.component.ts中:
@Input() candidates: CandidatesComponent;
addCandidate() { this.candidates.addCandidate( ... ) }
在candidates.component.ts中:
addCandidate(candidate: Candidate) {
this.candidateService.addCandidate(candidate);
var candidates = this.candidateService.getCandidates();
}
最后是不更新的视图 - candidates.component.html
<div *ngFor="let candidate of candidates" class="draggable candidate" data-id="{{candidate.id}}">{{candidate.name}}</div>
当我初始化组件时,列表按预期生成,但从schedule组件调用时不会更新。如何更改检测不会发现模型已更改?