問題描述
我正在嘗試在 ion-radio 元素上實現 ngModel,但不知何故它不起作用.這是我的代碼:
I'm trying to implement a ngModel on a ion-radio element but somehow it doesn't work. This is my code:
import {
Page
} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/settings/settings.html'
})
export class Settings {
constructor() {
this.unit = 2;
}
}
<ion-list radio-group>
<ion-list-header>
Unit
</ion-list-header>
<ion-item>
<ion-label>Metric (kg)</ion-label>
<ion-radio value="1" [(ngModel)]="unit"></ion-radio>
</ion-item>
<ion-item>
<ion-label>Imperial (lbs)</ion-label>
<ion-radio value="2" [(ngModel)]="unit"></ion-radio>
</ion-item>
</ion-list>
我嘗試在離子輸入和離子選擇上實現它,效果很好.我還嘗試將 directives: [FORM_DIRECTIVES]
添加到我的 @Page 并添加相應的導入,但這并不能解決問題.
I've tried implementing it on a ion-input and ion-select and that just works fine. I also tried adding directives: [FORM_DIRECTIVES]
to my @Page and added the corresponding import but that doesn't fix the problem.
有什么想法嗎?
推薦答案
語法已經改寫,ngModel
應該放在 ion-list
&radio-group
只有一次.無需將它們放在每個 ion-radio
元素上.
Syntax has been changed rewritten now, ngModel
should be place with ion-list
& radio-group
only once. No need to have them there on each ion-radio
element.
<ion-list radio-group [(ngModel)]="unit">
<ion-list-header>
Unit
</ion-list-header>
<ion-item>
<ion-label>Metric (kg)</ion-label>
<ion-radio value="1"></ion-radio>
</ion-item>
<ion-item>
<ion-label>Imperial (lbs)</ion-label>
<ion-radio value="2" ></ion-radio>
</ion-item>
</ion-list>
有關更多信息,您可以訪問 ionic2 框架論壇鏈接
For more information you could visit ionic2 framework forum link
這篇關于如何在離子無線電元件上使用 ngModel?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!