为什么控制器未定义?

时间:2015-05-19 18:40:52

标签: angularjs angularjs-controller

我在AngularJS中的Plunker分叉了一些代码,我正在尝试用John Papa's conventions重写它。

我收到错误:

  

参数'testCtrl as ctrl'不是函数,未定义

为什么?

(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);
                }
            }
        }
    }
}());

1 个答案:

答案 0 :(得分:1)

您的plunkr中使用的Angular版本不支持ControllerAs,请将其更新为更新版本。