我正在嘗試使用具有特定背景圖像的CSS類更新ng-class。例如:根據條件語句在控制器中更改ng-class
<button id="search" ng-class="{travel: travel }">Search</button>
for(var i = 0; i < arrayLength; i++) {
var descriptions = uniqueFilters[i].split(' ');
if(descriptions.indexOf('Travel') > -1) {
$scope.travel = "travel";
} else {
}
}}
我收到一個字符串數組。我把這些字符串,將這些句子分成單獨的單詞,然後如果他們有一個特定的單詞,更新這個類來應用特定的背景圖像。
我如何得到這個工作?
無論你在使用作爲條件的' ng-class',它需要是一個'boolean'值,而不是'string'。也許這樣做: '如果(descriptions.indexOf( '旅行')> -1){'' $ scope.travel = TRUE;' '}其他{' '}'' }' –