我在我的指令中使用了controllerAs
並且使用了bindToController
。 但是,控制器上的bindToController參數未定義。 DEMOangularjs bindToController的值在控制器中是未定義的
var myApp = angular.module('myApp',[]);
myApp.controller('MyController', function($scope){
$scope.change = function(){
$scope.fullname = 'Brian Kim';
}
});
myApp.directive('myDirective', function() {
return {
restrict: 'E',
scope: {
name: '='
},
controller: function() {
console.log(this.name); // undefined
},
controllerAs: 'ctrl',
bindToController: true,
template: '{{ctrl.name}}',
};
});
如何訪問在初始化時的參數?我需要它 – barteloma