1
我使用angular2 ngmodel下拉,我的觀點是沒有更新的時候我改變模型下拉值未ngmodel使用綁定angular2
//intialize the variable
addplanhours:any[];
this.addplanhours=[{name: '--sel--',value:0}, {name: 'Head start',value:1}, {name: 'Nice going',value:2},{name: 'On Track',value:3},{name: 'Keep On trying',value:4},{name: 'Making process',value:5},{name: 'Wrapping up',value:6}];
//function of electrifyonchange
electrifyonChange(value) {
for(var i=0;i<=this.addplanhours.length;i++){
this.electrify= value;
console.log("new value",this.electrify);
}
<span>
<span class="addnotefont1">Electrifying</span>
<select class="addplanpicker"[(ngModel)]="electrify" (ngModelChange)="electrifyonChange($event)">
<option *ngFor="let a of addplanhours" [ngValue]="a.value">{{a.name}} </option>
</select>
</span>
這是有點不清楚(至少對我來說),因爲這裏發生了什麼。你在哪裏改變模型,並在視圖中的哪個地方不反映變化? – Alex
–
好的......我以爲你會在* ngFor之外設置'electrify',顯然不是,但是這給我的第二個問題帶來了什麼,它在哪裏不會更新你的看法? – Alex