I've seen a couple posts, but for some reason I can't get my example to work. I even have old projects where this works fine, but the last two that I've attempted it has fallen flat.
The problem is I'm trying to pass a parameter back from my directive '&' inner function. I have two attacks, neither seem to work:
Attack1: Simply use the same callback name, nothing in link
angular.module('directiveBit', [])
.controller('tst', function($scope) {
$scope.thing = {
crazy: 'filler'
};
$scope.whenClicked = function(thing) {
console.log('the thing', thing);
$scope.thing = thing;
}
})
.directive('wok', function() {
return {
restrict: 'E',
template: '<button ng-click="clicked({s:1})">Click Me</button>',
scope: {
clicked: '&'
},
link: function(scope, element, attr) {
}
}
});
This seems to fail, the parameter sent into whenClicked is always undefined.
http://embed.plnkr.co/IpbIwzmxUrKgJqZ0DExI/script.js
Attack 2: Use the link function and call a different function within the directive:
angular.module('directiveBit', [])
.controller('tst', function($scope) {
$scope.thing = {
crazy: 'filler'
};
$scope.whenClicked = function(thing) {
console.log('the thing', thing);
$scope.thing = thing;
}
})
.directive('wok', function() {
return {
restrict: 'E',
template: '<button ng-click="doIt({s:1})">Click Me</button>',
scope: {
clicked: '&'
},
link: function(scope, element, attr) {
scope.doIt = function(theThing) {
scope.clicked({a: theThing});
}
}
}
});
Again this seems to fail. It calls the whenClicked function but still has nothing in the parameter.
http://embed.plnkr.co/VKXF5Yz2lYcKpKdS8pvE/script.js
Does anyone know what simple thing I'm missing here?