I've seen lots of these questions but haven't found a solution that works. here is a fiddle that doesn't work but should.
http://jsfiddle.net/cdparmeter/j2K7N/2/
Controller:
$scope.foo = function (textArray) { console.log(textArray) }; Directive:
return { restrict: 'E', replace: 'true', scope: { methodToCall: '&method' }, template: "<div> <input ng-model='textToPush'/> <button ng-click='pushText'>Push</button> <button ng-click='finish'>Finish</button> </div>", link: function (scope, element, attrs) { scope.paragraphs = []; scope.pushText = function () { scope.paragraphs.push(scope.pushText); scope.pushText = ""; } scope.finish = function () { scope.methodToCall(scope.paragraphs) } } } HTML:
<div ng-app="MyApp"> <div ng-controller="MyController"> <container data-method="foo"> </div> </div> I'm building an array inside my directive that needs custom handling in the controller of the parent scope. I know I can throw a watch in the parent scope on a model I pass into my directive but that seems hackish and dirty. any suggestions?