【问题标题】:How can i hide/show <ion-item> in popover?如何在弹出窗口中隐藏/显示 <ion-item>?
【发布时间】:2020-11-21 20:40:58
【问题描述】:

我正在尝试根据一些用户参数在弹出窗口中隐藏/显示链接,现在我尝试在“user.isAdmin”为假时隐藏管理链接。但是我似乎无法让它工作,即使我设置 *ngIf="true" 或 "1==1" 它也不会显示我试图隐藏。非常感谢您的帮助。

popover.component.html:

<ion-list>
  <ion-item>
    <ion-icon name="person-circle-outline"></ion-icon>
    <ion-button (click)="profil()" expand="block" fill="clear" shape="round">
      <ion-label>Profil</ion-label>
    </ion-button>
  </ion-item>

  <ion-item *ngIf="user.isAdmin == true">
    <ion-icon name="settings-outline"></ion-icon>
    <ion-button (click)="admin()" expand="block" fill="clear" shape="round">
      <ion-label>Admin</ion-label>
    </ion-button>
  </ion-item>

  <ion-item>
    <ion-icon name="log-out-outline"></ion-icon>
    <ion-button (click)="logut()" expand="block" fill="clear" shape="round">
      <ion-label>Log ut</ion-label>
    </ion-button>
  </ion-item>
</ion-list>

popover.component.ts:

import { Component, OnInit } from '@angular/core';


@Component({
  selector: 'app-popover',
  templateUrl: './popover.component.html',
  styleUrls: ['./popover.component.scss'],
})
export class PopoverComponent implements OnInit {

  user: any;

  constructor() {
    this.user = {
      isAdmin: true
    };

   }

ngOnInit() {}


}

【问题讨论】:

    标签: angular ionic-framework angular-ng-if


    【解决方案1】:

    例如,您可以使用ng-click="popover.hide()"

    <script id = "popover.html" type = "text/ng-template">
        <ion-popover-view>
          <ion-content>
            <div class="list" ng-click="popover.hide()">
              <a class="item" href="#/app/profit">
                Profit
              </a>
          
              <a class="item" href="#/app/company}">
                Company
              </a>
            </div>
          </ion-content>
        </ion-popover-view>
      </script>
    

    【讨论】:

    • 嗨,我是 angular 和 ionic 的新手,所以我可能错了,但我看不出这将如何解决问题,我的问题是无论我在 *ngIf 中输入什么="" 它不会显示 ,我认为如果它是真的就应该渲染它,如果它是假的就不要渲染它
    猜你喜欢
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-05
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多