Skip to content

Instantly share code, notes, and snippets.

@MasterHans
Last active October 6, 2021 08:45
Show Gist options
  • Save MasterHans/dde452b196ff7b3b2ba4669828474f96 to your computer and use it in GitHub Desktop.
Save MasterHans/dde452b196ff7b3b2ba4669828474f96 to your computer and use it in GitHub Desktop.
AndularJS - Pass Event into custom directive
//controller
angular.module('b1').controller('WarehousePurchaseEdit',
function () {
c.onPurchaseDateChange = function () {
alert(c.oldPurchaseDate);
}
)};
//view
<div ext-on-changes purchase="c.model" handler="c.onPurchaseDateChange()"></div>
//directive
angular.module('b1').directive("extOnChanges", function ($translate) {
return {
scope: {
purchase: '=',
handler: '&'
},
template: 'Current date: {{purchase.purchaseDate}}, current warehouse: {{purchase.warehouseName}}' +
'<button ng-click="s.clickFromDirective()">Call Controller function</button> ',
controllerAs: 's',
controller: function ($scope) {
var s = this;
s.clickFromDirective = function (){
// var params = {event: event, el: element};
$scope.handler();
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment