加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular4 – 如何在角度4中使用其他

发布时间:2020-12-17 07:40:55 所属栏目:安全 来源:网络整理
导读:我使用角度4,我想在这个例子中使用ngIf else: div *ngIf="isValid" content here .../divdiv *ngIf="!isValid" other content here.../div 如何用其他方式实现相同的行为? 角4.0.0决赛: 使用其他: div *ngIf="isValid;else other_content" content here
我使用角度4,我想在这个例子中使用ngIf else:
<div *ngIf="isValid">
  content here ...
</div>

<div *ngIf="!isValid">
 other content here...
</div>

如何用其他方式实现相同的行为?

角4.0.0决赛:

使用其他:

<div *ngIf="isValid;else other_content">
    content here ...
</div>

<ng-template #other_content>other content here...</ng-template>

你也可以使用其他的:

<div *ngIf="isValid;then content else other_content">here is ignored</div>

<ng-template #content>content here...</ng-template>
<ng-template #other_content>other content here...</ng-template>

或者一个人:

<div *ngIf="isValid;then content"></div>

<ng-template #content>content here...</ng-template>

演示:

Plunker

细节:

&LT纳克模板> :是Angular自己实现的< template>标签根据MDN:

The HTML <template> element is a mechanism for holding client-side content that is not to be rendered when a page is loaded but may subsequently be instantiated during runtime using JavaScript.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读