【发布时间】:2017-03-06 12:32:51
【问题描述】:
我用这样的 es6 风格实现了 Angular 项目:
controller.js
export default class InsertController {
constructor($scope) {
this.$scope =$scope;
this.data=[];
}
fillGrid(data) {
console.log(data);
}
}
InsertController.$inject = ['$scope'];
Directive.js
import angular from 'angular';
function FanGrid($compile) {
return {
replace: true,
restrict: 'E',
transclude: true,
link: function (scope, element, attrs) {
//I want access to fillGrid method of controller
scope.fillGrid(data);
}
}
}
export default angular.module('directives.fanGrid', [])
.directive('fanGrid', FanGrid)
.name;
现在我想知道
- 如何在指令中访问和调用控制器的
fillGrid()方法 - 如何从指令访问控制器类的
"this"
【问题讨论】:
标签: javascript angularjs angularjs-directive ecmascript-6