我的项目有一个大问题。我正在使用仅在 android 平台上工作的 *ngIf 。在iOS平台上不起作用。
我有以下 HTML 代码:
<GridLayout columns ="auto, auto" rows="*" (tap)="open()">
<StackLayout col="0" row ="0">
<label text="SomethingText"></label>
</StackLayout>
<StackLayout col="1" row ="0" *ngIf="sub">
<label text="Right"></label>
</StackLayout>
<StackLayout col="1" row ="0" *ngIf="!sub">
<label text="Bottom"></label>
</StackLayout>
</GridLayout>
在 TS 中我有:
sub: boolean = false;
public open() {
this.sub= !this.sub;
console.log('value',this.sub)
}
当我单击 View 中的功能时,显示不正确,显示为空、右侧、底部、底部等。
但函数中的控制台在每次点击时显示正确的 true 、 false 。
请问您能问我如何解决这个问题吗?
最佳答案
实现此目的的最佳方法是使用 ngif/else 而不是 2 个 ngif block 。
<StackLayout col="1" row ="0" *ngIf="sub === true; else elseBlock"><label text="Right"></label>
</StackLayout>
<ng-template #elseBlock> <StackLayout col="1" row ="0">
<label text="Bottom"></label>
</StackLayout></ng-template>
进一步阅读,您可以引用here .
关于ios - *ngIf 无法在使用 Nativescript 的 iOS 平台上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57903311/