ios - *ngIf 无法在使用 Nativescript 的 iOS 平台上工作

标签 ios angular nativescript angular-ng-if

我的项目有一个大问题。我正在使用仅在 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/

相关文章:

iphone - 尝试为 ios 应用程序安装映射软件时出现控制台错误

ios - 在 Flutter 中监听方向状态;旋转前后

iphone - EXEC_BAD_ACCESS (code=1 address=0x90000008) 切换 View Controller 时

ios - 如何确定当前的 iPhone/设备型号?

css - Angular 6 Material 检索 Material 颜色

node.js - 如何使用 angular-cli 加载包?

javascript - Angular Material 拖放 : Custom Pipe Issue

android - 使用 nativescript 的 openCV?

ios - 如何在 Nativescript IOS Webview 上更改用户代理或设置为桌面模式

javascript - NativeScript http.getJSON 和异步等待