0

ng-classCSSファイルから乗算ルールを設定するために呼び出されるディレクティブを使用しようとしています。ここにコードの一部があります

<div class="filterToggleBtn thumbnail" 
        ng-class="{ filterToggleBtnSide notificationColor:notificationState }">
</div>

変数filterToggleBtnSidenotificationColor、CSS ルールの文字列名が含まれています。

変数notificationStateセットtrueまたはfalse.

filterToggleBtnSide問題のポイントは、常にrule を使用する方法であり、その場合にnotificationColorのみnotificationState真になります。

私は以下のようなコードを作ろうとしていました

<div class="filterToggleBtn thumbnail" 
        ng-class="{ filterToggleBtnSide && notificationColor:notificationState }">
</div>

<div class="filterToggleBtn thumbnail" 
        ng-class="{ filterToggleBtnSide, notificationColor:notificationState }">
</div>

<div class="filterToggleBtn thumbnail" 
        ng-class="{ filterToggleBtnSide:true, notificationColor:notificationState }">
</div>

最後のサンプルでは、​​2 番目の式のみが機能しています。誰かが助けてくれれば、私は非常に感謝します;Dありがとう

4

1 に答える 1

1

仮定

$scope.filterToggleBtnSide = "class1";
$scope.notificationColor = "class2";

次のようなことができます。

<div class="filterToggleBtn thumbnail class1" 
ng-class="{class2:notificationState }"></div>
<!-- or this -->
<div class="filterToggleBtn thumbnail" 
ng-class="{class1: true, class2: notificationState}"></div>
<!-- or this -->
<div class="filterToggleBtn thumbnail class1
{{notificationstate && notificationColor}}"></div>
<!-- or this -->
<div class="filterToggleBtn thumbnail class1
{{notificationstate && 'class2'}}"></div>
<!-- or this -->
<div class="filterToggleBtn thumbnail 
{{filterToggleBtnSide}} {{notificationstate && notificationColor}}"></div>
<!-- or this -->
<div class="filterToggleBtn thumbnail 
{{filterToggleBtnSide}} {{notificationstate && 'class2'}}"></div>
于 2013-08-23T11:07:36.513 に答える