I want to create some event handler in my directive`s controller. Here is directive code:
module.exports = function() {
return {
restrict: 'EA',
bindToController: true,
scope: {
myarticle: '=article'
},
controllerAs: 'ctrl',
templateUrl: '../../views/draggableArticle.html',
link: function(scope, element, attr) {
},
controller: function() {
this.clicked = function() {
alert('clicked');
};
this.dragstartHandler = function() {
alert('draged');
};
}
};
};
And my view:
<div draggable="true" ondragstart="ctrl.dragstartHandler($event);" ng-click="ctrl.clicked()">
<h2></h2>
<p></p>
</div>
When I click on the block it works and alert "clicked", but when i drag a block it gives me an error
Uncaught ReferenceError: ctrl is not defined
Aucun commentaire:
Enregistrer un commentaire