我正在尝试在 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模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)