3
active
変数に基づいてHTML見出しをアクティブ/非アクティブにしようとしています。条件に基づいてng-repeat内のHTML要素にCSSクラスを適用
<div ng-init="active = 1">
<h4 ng-repeat="(key, val) in vm.headings" ng-click="active = $index" ng-class="{'active': active === $index}">
{{key}}
</h4>
</div>
見出しオブジェクト::しかし、私はng-repeat
ディレクティブの$index
変数使用しています見出しをクリックすることでactive
フラグを設定する
vm.headings = {
"HEADING_1": "CONTENT",
"HEADING_2": "CONTENT",
"HEADING_3": "CONTENT"
};
最初のロードでは、見出しの一つは、「active`に表示されますセットとして。しかし、その後のクリックでは、望ましい結果が得られません。すべての見出しは、クリックするとアクティブになります。コントローラで
<h4 ng-repeat="(key, val) in vm.headings" ng-click="selectH($index)" ng-class="{'active': active === $index}">
問題の詳細については、次のURLを参照してください。http://stackoverflow.com/questions/17925355/how-can-i-use-the-index-inside-a-ng-repeat-to-enable-a-class- and-show-a-div – Dese