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>{{ctrl.myarticle.webTitle | limitTo: 40}}</h2>
<p>{{ctrl.myarticle.blocks.body[0].bodyTextSummary | limitTo: 200}}</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