2017-08-28 125 views
0

my.component.html:隐藏的元素闪烁

<div [hidden]=shouldHideErrorMessage()>Error!</div> 

my.component.ts:

public shouldHideErrorMessage(): boolean { 
     return this.Property == null || this.Property.IsGood 
    } 

酒店最初为null,所以shouldHideErrorMessage()返回true。但是当加载时,错误消息在屏幕上闪烁。我怎样才能防止呢?

+2

使用'* ngIf'不是一种选择吗? – Faisal

+0

我觉得你的病情不清楚,如果检查为空,为什么this.Property.IsGood –

回答

2

由于费萨尔建议,使用* ngIf防止问题:

<div *ngIf="shouldShowErrorMessage()">Error!</div> 
+0

你也可以这样做:'

Error!
' – Faisal

0

这样 在你component.ts

public shouldHideErrorMessage(): boolean { 
    if(this.Property == null){ 
    return true; 
    } 
    return false; 
} 

和你component.html

<div *ngIf="shouldHideErrorMessage()">Error!</div> 
更好地利用