错误:[ng:areq]参数' ScenariosViewCtrl'不是一个功能,未定义

时间:2016-01-26 08:33:52

标签: javascript angularjs

我在一个页面上有2个控制器:ScenariosViewCtrl和StoriesViewCtrl。 StoriesViewCtrl工作正常,但对于ScenariosViewCtrl我有一个错误:参数' ScenariosViewCtrl'不是一个功能,未定义。

它们都以相同的方式在单独的文件中声明:

scenariosview.controller.js

(function (){
    'use strict';
    function ScenariosViewCtrl() {
...
    };

    var app = angular.module('testLab');

    app.controller('ScenariosViewCtrl', function ($scope) {
        $scope.players = "testing";
    });

});

storiesview.contoller.js

(function (){
    'use strict';
    function StoriesViewCtrl() {
    ...
    };
    var app = angular.module('testLab');

    app.controller('StoriesViewCtrl', function ($scope) {
        $scope.players = "testing";
    }); 
});

我有两个单独的指令 scenariosview.directive.js:

(function () {
    'use strict';
    function scenariosviewDirective () {
        return {
            restrict: 'E',
            controller: 'ScenariosViewCtrl',
            controllerAs: 'scenariosViewCtrl',
            templateUrl: './Content/app/components/projectExplorer/scenariosExplorer/scenariosView/scenariosview.html',
            link: function (scope, element, attrs) {

            },
        };
    };
    angular.module('testLab').directive('rlScenariosView', scenariosviewDirective);
})();

storiesview.directive.js

(function () {
    'use strict';
    function storiesviewDirective () {
        return {
            restrict: 'E',
            controller: 'StoriesViewCtrl',
            controllerAs: 'storiesViewCtrl',
            templateUrl: './Content/app/components/projectExplorer/scenariosExplorer/scenariosView/scenariosview.html',
            link: function (scope, element, attrs) {

            },
        };
    };
    angular.module('testLab').directive('rlStoriesView', scenariosviewDirective);
})();

我的scenarioview.html:

<div class="row">
    <div class="col-xs-6 col-md-3">
        <div class="panel panel-info">
            <div class="panel-heading">
                <div class="btn-group">
                    <a href="#" class="btn btn-default btn-lg glyphicon fa-folder-o" data-toggle="tooltip" title="New Folder"></a>
                    <a href="#" class="btn btn-default btn-lg glyphicon icon-book-open" data-toggle="tooltip" title="New Story"></a>
                    <a href="#" class="btn btn-default btn-lg glyphicon icon-note" data-toggle="tooltip" title="Edit Story"></a>
                    <a href="#" class="btn btn-default btn-lg glyphicon fa-remove" data-toggle="tooltip" title="Remove"></a>
                </div>
            </div>
            <div>
                <div class="well wd-wide">
                    <abn-tree tree-data="storiesViewCtrl.data" tree-control="storiesViewCtrl.control" expand-level="2"></abn-tree>
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-6 col-md-9">
        <div class="panel panel-info panel-default">
            <div class="panel-heading">
                <div class="btn-group">
                    <a href="#" class="btn btn-default btn-lg glyphicon icon-plus" data-toggle="tooltip" title="Add Scenario"></a>
                    <a href="#" class="btn btn-default btn-lg glyphicon fa-beer" data-toggle="tooltip" title="Add Background"></a>
                    <a href="#" class="btn btn-default btn-lg glyphicon fa-save" data-toggle="tooltip" title="Save Changes"></a>
                </div>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:2)

  1. 定义模块时,必须定义其依赖关系 -
    angular.module('testLab', []);(也许你在另一个文件中定义它?)

  2. 这没有任何意义:

    function ScenariosViewCtrl() {
       ...
    };
    
    var app = angular.module('testLab');
    
    app.controller('ScenariosViewCtrl', function ($scope) {
        $scope.players = "testing";
    })
    

    也许你的意思是:

    function ScenariosViewCtrl($scope) {
       $scope.players = "testing";
    };
    
    var app = angular.module('testLab');
    
    app.controller('ScenariosViewCtrl', ScenariosViewCtrl);
    
  3. 您无法创建具有相同名称rlScenariosView的2条指令。