<div ng-app="myApp">
<div greeting ng-click="greeting()">directive</div>
</div>
Is there a way to call a method when the template loads in AngularJS? I attempted to use ng-init
, but it did not work as expected.
angular.module('myApp', [])
.directive('greeting', function() {
return {
restrict: 'A',
link: function($scope, element, attrs, controller) {
element.on('click',function(){
alert('clicked');
});
element.on("load", function(){
alert("loaded");
});
}
};
}
);