我是Ionic的新手。我想在Array1
和Array2
中将切换值更新为状态(激活和停用)。当我在Array1
中更新状态时,它也在Array2
中更新。我只想更新一种状态。
我正在使用Ionic 4和Angular7
second.page.ts
ionViewWillEnter(i){
let task = this.activeRoute.snapshot.paramMap.get('i'); //get value from array with the help of router
this.tasks = this.dataService.getTask();
let updatedToggleStatus = this.dataService.getStatus();
if(updatedToggleStatus == false){
this.deactive = false;
}
else if(updatedToggleStatus == true){
this.deactive = true;
}
}
statusActive(){
var toggleStatus = this.deactive;
let i = this.activeRoute.snapshot.paramMap.get('i');
this.tasks = this.dataService.getTask();
this.dataService.statusToggle(toggleStatus,i);
}
data.service.ts
statusToggle(toggleStatus,i){
if(toggleStatus == false){
this.togStatus = toggleStatus;
console.log('deactivated');
}
else if(toggleStatus == true){
this.togStatus = toggleStatus;
console.log('activated');
console.log(this.togStatus,'tog')
}
}
getStatus(){
// console.log(i)
return this.togStatus;
}
我只想更新一个阵列状态,但是两个阵列状态都可以通过单击切换来更新
答案 0 :(得分:0)
在模板代码中:
<ion-toggle [(ngModel)]="toggle01" (ionChange)="toggleTwo()"></ion-toggle>
<ion-toggle [(ngModel)]="toggle02" (ionChange)="toggleOne()"></ion-toggle>
在组件代码中声明两个布尔值和两个函数,如下所示:
toggle01: boolean = true;
toggle02: boolean = false;
.......
toggleOne() {
this.toggle01 = !this.toggle02;
}
toggleTwo() {
this.toggle02 = !this.toggle01;
}
,这应该可以很好地工作!