角度2のバグが見つかったかどうかわかりませんでした。基本的には、選択ボックスから選択したオプションの選択リストのリストを作成し、項目が選択されると、前の項目の下に新しい空の選択ボックスが作成され、ユーザーは選択した項目を継続的に追加できます。角度2 ngModelの選択ボックスの変更が更新されない
ボトムセレクトボックスを空の値に戻したいのですが、ngModelの値を0(または空)に戻すと、以前に選択したオプションでボトムセレクトボックスが保持されます。
@Component({
selector: 'my-app',
template: `
<div *ngFor="let a of arr">
<div *ngFor="let b of a.entities;let i = index">
<select class="form-control input-sm" [(ngModel)]="a.entities[i]">
<option *ngFor="let c of items" value="{{c}}">{{c}}</option>
</select>
</div>
<select class="form-control input-sm mb5" (change)="entitySelect(a)" [(ngModel)]="a.selected">
<option value="0">- Select -</option>
<option *ngFor="let c of items" value="{{c}}">{{c}}</option>
</select>
</div>
`,
})
export class App {
items:Array<string> = ['red','green','blue'];
constructor() {
this.arr = [{
entities: [],
selected: 0
}]
}
entitySelect(entity) {
entity.entities.push(entity.selected);
entity.selected = 0; // Revert bottom select box back to empty
}
}
https://plnkr.co/edit/PMzbgEtyd4DFhObu1UVz
私が設定している場合、他の奇妙なことは、それが唯一の最初の選択で、青に最後の選択ボックスをデフォルト設定されます、「青」の代わりに、0と言ってentity.selectedされます。それ以降は、前の選択と同じままです。
https://plnkr.co/edit/Ze5uS1JjAmI7QXjQ17kQ
それは働いた。ありがとう! – Scot