I have this fiddle that shows a directive that has an alert for now. There is also a controller that has alert. This is all working fine except for the fact that the binding is being lost for the text to be shown on the button. Any ideas to help me?
<div ng-app="directiveApp" ng-controller="MainController">
<button ng-click="doStuff()" unsaved-warning-trigger>
{{buttonText}}
</button>
</div>
var app = angular.module("directiveApp", []);
app.directive('unsavedWarningTrigger',
function() {
return {
priority: 1,
terminal: true,
link: function (scope, element, attr) {
var clickAction = attr.ngClick;
element.bind('click',function () {
if (window.confirm("Sure?")) {
scope.$eval(clickAction)
}
});
}
};
}
);
MainController = function($scope) {
$scope.buttonText = 'bound button';
$scope.doStuff = function () {
alert("doing stuff");
};
}