I\'ve created a directive in Angular that looks like this:
angular.module(\'msfApp\')
.directive(\'listitem\', function () {
return {
@Macros answer made it work just fine for me! Here's my finished code:
Directive template file:
{{item.productName}}
{{item.variants[0].listprice.amount}} {{item.variants[0].listprice.entity}}
Directive:
angular.module('msfApp')
.directive('listitem', function () {
return {
templateUrl: 'assets/templates/directives/listitem.html',
restrict: 'E',
scope: {
'item': '=',
'itemClick': '='
},
link: function(scope, iElement, iAttrs) {
scope.selected = false;
scope.toggleState = function(item) {
scope.selected = !scope.selected;
scope.itemClick(item);
}
}
}
});
Directive implementation:
Function in the Controller:
$scope.toggleInBasket = function(item) {
$scope.basket.toggle(item);
console.log(basket.get());
}