Is it possible to invoke a controller class method using ES6 syntax from a directive template in AngularJS?
For example, consider the following directive:
import angular from 'angular';
function dpGrid() {
return {
restrict: 'E',
scope: {
options: '='
},
template: require('./grid.directive.html')
}
}
export default angular.module('directives.dpGrid', [])
.directive('dpGrid', dpGrid)
.name;
A snippet from the directive template:
<a class="btn btn-info" ng-click="delete(item)">delete</a>
I am looking to call the delete() method of a controller from the directive template. The controller is defined as follows:
export default class userController {
constructor($scope) {
this.$scope=$scope;
}
delete(item){
console.log("item : ",item);
}
}
userController.$inject = ['$scope'];
The challenge is that I cannot use the controller attribute in the directive due to the need to work with multiple controllers.