I am using Angular 4 and Typescript, I have a table of <select>s in my template:
<tr *ngFor="let task of tasksDetails">
<td>{{task.name}}</td>
<td>
<select class="form-control" [(ngModel)]="task.uiMetadata.worker">
<option value="">Select worker</option>
<option *ngFor="let worker of workers" [value]="worker.resource.id">{{worker.resource.name}}</option>
</select>
</td>
</tr>
Within another component I am able to add/remove to the workers list and it is output to a Subject which this component subscribes to:
this.workerRemoved.subscribe(worker => {
_each(this.tasksDetails, taskTemplate => {
if (taskTemplate.uiMetadata.worker === member.resourceId) {
taskTemplate.uiMetadata.worker = '';
}
});
});
The problem is that while the subscription updates the field in the variable, ngModel is not picking up the change and reflecting it in the UI.
So we end up with the situation where ng-reflect-model is showing "11", the worker variable is an empty string, and the select shows as blank because the "11" option has been removed.
How do I get Angular to keep the model in sync with the change I made in the subscription? I have tried wrapping it in an NgZone.run() and also calling ChangeDetectorRef.detectChanges() but neither would update the ng-reflect-model value.
