javascript - 如何有条件地隐藏 native 脚本( Angular )中的选项卡项目?

标签 javascript nativescript angular2-nativescript

在 NativeScript Angular 应用程序中隐藏 tabViewItems 的推荐方法是什么。

我尝试将 ngIf 指令与 ng-template 结合使用,但似乎并不完全支持它。

这是我正在使用的代码

<TabView [selectedIndex]="auth.user ? 2 : 4" class="tab-view" sdkExampleTitle sdkToggleNavButton>
      <!--shown when logged in-->
      <ng-template [ngIf]="auth.user">
        <!--notifications tabs-->
        <StackLayout *tabItem="{title: 'notifications', iconSource: 'res://ic_action_home'}">
          <Label text="NativeScript" class="m-15 h2 text-left" color="blue"></Label>
          <ScrollView>
            <Label text="content" textWrap="true" class="m-15"></Label>
          </ScrollView>
        </StackLayout>
        <!--messages tabs-->
        <StackLayout *tabItem="{title: 'Messages', iconSource: 'res://ic_action_home'}">
          <Label text="NativeScript" class="m-15 h2 text-left" color="blue"></Label>
          <ScrollView>
            <Label text="content" textWrap="true" class="m-15"></Label>
          </ScrollView>
        </StackLayout>
      </ng-template>
      <StackLayout *tabItem="{title: 'People', iconSource: 'res://ic_action_home'}">
        <Label text="NativeScript" class="m-15 h2 text-left" color="blue"></Label>
        <ScrollView>
          <Label text="content" textWrap="true" class="m-15"></Label>
        </ScrollView>
      </StackLayout>
      <StackLayout *tabItem="{title: 'Home', iconSource: 'res://ic_action_home'}">
        <RadListView [items]="announcementService.announcements" loadOnDemandMode="Auto" class="list-group">
          <ListViewLinearLayout tkListViewLayout scrollDirection="Vertical" itemInsertAnimation="Slide" itemDeleteAnimation="Default">
            <ng-template tkListItemTemplate let-item="item">
              <GridLayout class="list-group-item" rows="*" columns="auto, *">
                <Image row="0" col="0" decodeWidth="60" decodeHeight="60" loadMode="async" src="res://icon" class="thumb img-rounded"></Image>
                <StackLayout row="0" col="1">
                  <Label [text]="item.title" textWrap="true" class="list-group-item-heading"></Label>
                  <Label class="list-group-item-text" [text]="item.createdAt | amTimeAgo"></Label>
                </StackLayout>
              </GridLayout>
            </ng-template>
          </ListViewLinearLayout>
        </RadListView>
      </StackLayout>
    </TabView>

当将 ng-template 与 ngIf 一起使用时,它第一次可以工作,但重新加载应用程序后它就不再工作了。

我尝试了 [visibility] = "..condition.. ? 'visible': 'collapse'",但没有成功。

我做错了什么?

最佳答案

像这样的东西可能会起作用:

<ng-container *ngIf="isLoggedIn()">
  <StackLayout>
    // ...
  </StackLayout>
</ng-container>

关于javascript - 如何有条件地隐藏 native 脚本( Angular )中的选项卡项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245760/

相关文章:

javascript - Parallax.js 移动我的 css 定位元素

javascript - Firefox 上的 Angular 指令

Nativescript-iOS应用名称?

android - 如何在 Nativescript ExoPlayer 中使用事件?

android - ANDROID_HOME 环境变量未设置或指向 Ubuntu 中不存在的目录

tabs - 在 NativeScript TabView 中隐藏选项卡按钮

Javascript 键/值与数组配对

javascript - 如何将自定义 JavaScript 添加到我的 Rails3 View 中?

xcode - "Products contains invalid products"Nativescript Xcode 存档

css - 如何在 NativeScript 中将按钮固定到底部屏幕