为什么控制器未定义?
Why controller as is undefined?
我已经在 Plunker in AngularJS and am trying to rewrite it with John Papa's conventions 上分叉了一些代码。
我收到一个错误:
Argument 'testCtrl as ctrl' is not a function, got undefined
为什么?
(function() {
angular.module('Test', [])
.controller('testCtrl', testCtrl)
.directive('testDirective', testDirective);
function testCtrl() {
var vm = this;
vm.options = {};
vm.callMe = function() {
console.log("called from crontroller");
vm.options.method1("something");
};
}
function testDirective() {
return {
restrict: "E",
scope: {
options: '='
},
link: function(scope, element, attrs) {
scope.options.method1 = function(message) {
console.log("called from crontroller: " + message);
}
}
}
}
}());
您的plunkr中使用的Angular版本不支持ControllerAs,请更新至较新版本。
我已经在 Plunker in AngularJS and am trying to rewrite it with John Papa's conventions 上分叉了一些代码。
我收到一个错误:
Argument 'testCtrl as ctrl' is not a function, got undefined
为什么?
(function() {
angular.module('Test', [])
.controller('testCtrl', testCtrl)
.directive('testDirective', testDirective);
function testCtrl() {
var vm = this;
vm.options = {};
vm.callMe = function() {
console.log("called from crontroller");
vm.options.method1("something");
};
}
function testDirective() {
return {
restrict: "E",
scope: {
options: '='
},
link: function(scope, element, attrs) {
scope.options.method1 = function(message) {
console.log("called from crontroller: " + message);
}
}
}
}
}());
您的plunkr中使用的Angular版本不支持ControllerAs,请更新至较新版本。