如何最好的条件模板显示在角度4 [英] how to best conditional template show in angular 4
本文介绍了如何最好的条件模板显示在角度4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我的练习角度为4.普通用户查看此内容后会显示公共内容.注册用户进入网页后会显示编辑内容或某些内容.最佳做法如何有条件地显示模板或一些HTML内容示例:
currently, i am practiced angular 4. when a normal user view this then show public content When A Registered user enter the web page then show edit or some content. how to the best practices show conditionally template Or Some Html Contents Example:
<div *ngIf="isUser">
some Content here......
</div>
<div *ngIf="!isUser">
some Content here .....
</div>
实际上,我想知道如何做到最好.
actually, i want to know how to the best.
推荐答案
在angular 4中,您可以将if .. else ..结构用于html模板
In angular 4 you can use if.. else.. structure for html templates
您可以通过以下方式使用它:
You can use it in this way:
<div *ngIf="isUser; else otherContent">
some Content here......
</div>
<ng-template #otherContent>
<div>
some Content here .....
</div>
</ng-template>
但是对于您而言,最漂亮的解决方案是...如果...那么...否则...有条件的
but in your case, the prettiest solutions will be if... then... else... conditional
<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>
这篇关于如何最好的条件模板显示在角度4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文