2016-01-13 66 views
1

我的HTML是這樣的:把條件

<div data-ng-attr-style="background:url({{ backgroundImage}}) !important; background-size:cover;" ></div> 

現在我可以把條件下的雙大括號{{只內。

但是如果我提出一個條件就會中斷。

我想有這樣的條件:

data-ng-attr-style="condition ? {background:url({{ backgroundImage}}) !important; background-size:cover;} : {display:none}" 

請幫助。

回答

0

你需要把你的病情在{{}}:

data-ng-attr-style="{{ condition ? 'background:url(' + backgroundImage + ') !important; background-size:cover' : 'display: none' }}" 

或者你把幾行以提高可讀性:

data-ng-attr-style="{{ 
    condition 
     ? 'background: url(' + backgroundImage + ') !important; background-size: cover;' 
     : 'display: none' 
}}"