Last active
October 6, 2021 08:45
-
-
Save MasterHans/dde452b196ff7b3b2ba4669828474f96 to your computer and use it in GitHub Desktop.
AndularJS - Pass Event into custom directive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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