Angular で次のようなディレクティブを作成しました。
angular.module('msfApp')
.directive('listitem', function () {
return {
templateUrl: 'assets/templates/directives/listitem.html',
restrict: 'E',
scope: {
'item': '='
}
}
});
テンプレートは次のようになります。
<div class="tsProductAttribute" ng-click="toggleInBasket(item)">
<span class="tsProductAttribute-image">
<img ng-src="{{item.variants[0].image}}">
</span>
<span class="tsProductAttribute-desc">{{item.productName}}</span>
<span class="tsProductAttribute-price">{{item.variants[0].price[0].amount}} {{item.variants[0].price[0].entity}}</span>
</div>
しかし今、私は2つの質問があります:
- コントローラーで ng-click 関数が起動しません
toggleInBasket(item)
。なぜですか? - 次に、トグル動作をリスト項目に追加して、「tsProductAttribute--selected」というクラスを切り替えるにはどうすればよいですか
よろしくお願いします!