3 回答

TA貢獻2041條經(jīng)驗 獲得超4個贊
使用[value] =“ 1”代替value =“ 1”
<input name="options" ng-control="options" type="radio" [value]="1" [(ngModel)]="model.options" ><br/>
<input name="options" ng-control="options" type="radio" [value]="2" [(ngModel)]="model.options" ><br/>
編輯:
如所建議的通過thllbrg“對于角度2.1+使用[(ngModel)],而不是[(ng-model)]”

TA貢獻1853條經(jīng)驗 獲得超18個贊
我的手動解決方法model.options是在選擇新的單選按鈕時手動進行更新:
template: `
<label *ngFor="let item of radioItems">
<input type="radio" name="options" (click)="model.options = item"
[checked]="item === model.options">
{{item}}
</label>`
class App {
radioItems = 'one two three'.split(' ');
model = { options: 'two' };
}
這Plunker演示了上面的內(nèi)容,以及如何使用按鈕來更改所選的單選按鈕-即證明數(shù)據(jù)綁定是雙向的:
<button (click)="model.options = 'one'">set one</button>
添加回答
舉報