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

如何在角度4中显示最佳条件模板

发布时间:2020-12-17 06:56:55 所属栏目:安全 来源:网络整理
导读:目前,我练习角度4.当普通用户查看此时显示公共内容当注册用户进入网页然后显示编辑或某些内容.如何最佳实践显示有条件的模板或一些 Html内容示例: div *ngIf="isUser" some Content here....../divdiv *ngIf="!isUser" some Content here ...../div 实际上,
目前,我练习角度4.当普通用户查看此时显示公共内容当注册用户进入网页然后显示编辑或某些内容.如何最佳实践显示有条件的模板或一些 Html内容示例:

<div *ngIf="isUser">
    some Content  here......
</div>
<div *ngIf="!isUser">
    some Content here .....
</div>

实际上,我想知道如何做到最好.

解决方法

在角度4中,您可以使用if .. else ..结构用于html模板

您可以这样使用它:

<div *ngIf="isUser; else otherContent">
    some Content  here......
</div>
<ng-template #otherContent>
    <div>
        some Content here .....
    </div>
</ng-template>

但在你的情况下,最漂亮的解决方案将是……然后……其他……有条件的

<ng-container *ngIf="isUser; then someContent else otherContent"></ng-container>

<ng-template #someContent ><div>some content...</div></ng-template>
<ng-template #otherContent ><div>other content...</div></ng-template>

(编辑:李大同)

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

    推荐文章
      热点阅读