Angular 5选择在更新阵列后冻结的选项

时间:2018-03-21 21:33:06

标签: javascript angular drop-down-menu

我有一个选择下拉列表:

<select class="form-control" id="teamSelect" [disabled]="!isSubmitButtonDisabled()" [(ngModel)]="selectedTeam" (ngModelChange)="onTeamChange($event)" style="width: 50%;">
  <option *ngFor="let team of teams" [ngValue]="team">{{ team.text }}</option>
</select>

我在ngOnit填充它:

ngOnInit() {
    this._microService.getTeams()
        .subscribe(team => {
            this.teams = team.map(m => { return { text: m.name, value: m.name } as Select; });
            this.teams.unshift( { text: '', value: ''} as Select)
        }
        );
}

没问题!

稍后我点击按钮会在下拉列表中添加新项目...

onCreateTeam(team: string = ''): void {
    if(team != '') {
        let t = { text: team, value: team }  as Select;
        this.teams.push(t);
        this.selectedTeam = t;
    }
}

下拉列表已填充但我无法选择任何内容。有没有办法从我的组件更新let team of teams中的数组,以便DOM获得新选项,并且仍允许选择?

控制台中不会抛出任何错误。

0 个答案:

没有答案