【发布时间】:2016-12-21 17:58:06
【问题描述】:
我在我的应用程序中使用 Angular2 和 ionic2。在这里,我有一个切换。当切换关闭时,我不应该允许用户选择复选框。它对我来说工作正常。问题是当我在切换打开时选择复选框,如果我再次关闭它,那些被选中的复选框应该被重置。
谁能帮我解决这个问题?
我的代码在下面 app.html
<ion-content>
<ion-item class="toggle">
<ion-label>App Explore</ion-label>
<ion-toggle class="center" [(ngModel)]="exploreOn" (ionChange)="toggleChange()"></ion-toggle>
</ion-item>
<div class="urban">
<div class="ck-button" *ngFor="let slide of tags; let i = index">
<label>
<input type="checkbox" value="1" [disabled]="checkboxDisabled" [(ngModel)]="selectname">
<span>{{slide.tag}} </span>
</label>
</div>
</div>
app.ts
export class AppPage {
selectname: boolean = false;
exploreOn: boolean = false;
checkboxDisabled = true;
checkboxEnabled = false;
public posts: any;
tags: any;
constructor(public navCtrl: NavController, public http: Http) {
this.http.get('./mockAPI/chatList.json').subscribe(
data => {
this.posts = data.json();
this.tags = this.posts.tags;
console.log("data", this.tags);
});
}
toggleChange() {
if (this.exploreOn != true) {
this.checkboxDisabled = true;
this.selectname = false;
}
else {
this.checkboxDisabled = false;
}
}
**My josn file lies below**
"tags": [
{
"id": 1,
"tag": "#jetset"
},
{
"id": 2,
"tag": "#retailtherapy"
},
{
"id": 3,
"tag": "#eatsipgroove"
}
]
【问题讨论】:
标签: angular typescript ionic2