Angular 2隐藏条件

时间:2017-08-24 00:11:20

标签: angular angular2-template

我正在使用*ngIf来有条件地显示一段可以正常工作的代码块。

但是我需要使用[hidden]display:none来实际隐藏dom中的块。据我了解,我只能提供truefalse [hidden]

如何使用[hidden][class]从Dom中有条件地隐藏此内容?

<div *ngIf="raid != -1;">
    <p>Need to display:none inside of this</p>
</div>

1 个答案:

答案 0 :(得分:1)

您必须在标记中添加隐藏选项:

<p [hidden]="true">Need to display:none inside of this</p>

并用变量名

替换“”中的true

或者如果您只想隐藏文本的一部分:

<p>some text <span [hidden]="true">this will be hidden (or not) </span>some more text</p>