【问题标题】:*ngIf doesn't working in iOS platform using Nativescript*ngIf 在使用 Nativescript 的 iOS 平台上不起作用
【发布时间】:2019-09-12 09:05:27
【问题描述】:

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

当我点击视图中的函数时显示不正确,显示为空、右、下、下等。

但控制台在每次点击时显示正确的 true , false 。

请问,你能问我如何解决这个问题吗?

【问题讨论】:

  • 你能分享一个可以重现问题的 Playground 示例吗?

标签: ios angular nativescript angular-ng-if


【解决方案1】:

实现这一点的最佳方法是使用 ngif/else 而不是使用 2 个 ngif 块。

<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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    相关资源
    最近更新 更多