Ngfor 的问题仅支持绑定到 Iterables,例如 Arrays
Issue with Ngfor only supports binding to Iterables such as Arrays
错误
类型为“string
”的支持对象 'Active'。 NgFor
仅支持绑定到 Iterables,例如数组。
我试图让它在每次单击切换时都会将 {{ setting }}
从非活动状态更改为活动状态。如果另一种方法不可行,则试图使这种方法起作用。
代码html:
<ion-item>
<ion-label>Front Door</ion-label>
<ion-toggle [(ngModel)]="fdoor" ng-model="ni_toggle" (ionChange)="Fdoor()" (click)="change()"></ion-toggle>
</ion-item>
<div *ngFor="let setting of sett">
{{ setting }}
</div>
ts:
active: string = "Active"
inactive: string = "Inactive"
change() {
if(this.fdoor = true) {
this.sett = this.active
}
}
我不知道你的目的是什么。但我认为你应该这样做:
sett = false;
change() {
if(this.fdoor = true) {
this.sett = !this.sett;
}
}
HTML
<ion-item>
<ion-label>Front Door</ion-label>
<ion-toggle [(ngModel)]="fdoor" ng-model="ni_toggle" (ionChange)="Fdoor()" (click)="change()"></ion-toggle>
</ion-item>
<div>
{{ sett ? "Active" : "Inactive" }}
</div>
错误
类型为“string
”的支持对象 'Active'。 NgFor
仅支持绑定到 Iterables,例如数组。
我试图让它在每次单击切换时都会将 {{ setting }}
从非活动状态更改为活动状态。如果另一种方法不可行,则试图使这种方法起作用。
代码html:
<ion-item>
<ion-label>Front Door</ion-label>
<ion-toggle [(ngModel)]="fdoor" ng-model="ni_toggle" (ionChange)="Fdoor()" (click)="change()"></ion-toggle>
</ion-item>
<div *ngFor="let setting of sett">
{{ setting }}
</div>
ts:
active: string = "Active"
inactive: string = "Inactive"
change() {
if(this.fdoor = true) {
this.sett = this.active
}
}
我不知道你的目的是什么。但我认为你应该这样做:
sett = false;
change() {
if(this.fdoor = true) {
this.sett = !this.sett;
}
}
HTML
<ion-item>
<ion-label>Front Door</ion-label>
<ion-toggle [(ngModel)]="fdoor" ng-model="ni_toggle" (ionChange)="Fdoor()" (click)="change()"></ion-toggle>
</ion-item>
<div>
{{ sett ? "Active" : "Inactive" }}
</div>