错误:ng:areq - 不同文件中的控制器

时间:2016-01-09 23:14:41

标签: angularjs

我正在尝试将我的角度应用中的每个控制器分开,但我有这个错误:

23:51:38.389 "Error: [ng:areq] http://errors.angularjs.org/1.5.0-rc.0/ng/areq?p0=skillsController&p1=not%20a%20function%2C%20got%20undefined
P/<@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:6:421
sb@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:22:41
Ta@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:22:128
af/this.$get</<@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:84:42
B@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:62:118
v@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:63:115
Vf/<@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:72:397
e/<@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:123:217
pf/this.$get</m.prototype.$eval@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:137:442
pf/this.$get</m.prototype.$digest@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:135:33
pf/this.$get</m.prototype.$apply@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:138:234
g@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:91:372
t@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:95:492
ag/</v.onload@file:///C:/Users/Piotr/Desktop/ver%202/js/angular.min.js:97:31
"1 angular.min.js:111:399
e/<() angular.min.js:111
cf/this.$get</<() angular.min.js:84
e/<() angular.min.js:123
pf/this.$get</m.prototype.$eval() angular.min.js:137
pf/this.$get</m.prototype.$digest() angular.min.js:135
pf/this.$get</m.prototype.$apply() angular.min.js:138
g() angular.min.js:91
t() angular.min.js:95
ag/</v.onload() angular.min.js:97

pkApp.js:

angular.module('pkApp', ['Controllers']).value("version", "1.160110");

controllersModule.js:

angular.module('Controllers', []);

skillsController.js:

angular.module('Controllers', [])
    .controller('skillsController', ['$scope', function($scope){
        $scope.skills = [
            "html",
            "css",
            "js",
            "jquery",
            "angularjs",
            "php",
            "mysql",
            "joomla"
        ];
    }]);

portfolioController.js:

angular.module('Controllers', [])
    .controller('portfolioController', ['$scope', function($scope) {
        $scope.sites = [{
            name: "Site1",
            href: "http://www.site1.pl",
            img: "1"
        }, {
            name: "Site 2",
            href: "http://www.site2.pl",
            img: "2"
        }, {
            name: "Site 3",
            href: "http://www.site3.pl",
            img: "3"
        }];
    }]);

看起来像角度看到新模块,只有第一个控制器,它接下来被视为功能? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

一个简单的解决方案可能是:

  1. 使用pkApp.js中的模块定义变量

    var app = angular.module('pkApp', []);
    
  2. 您可以删除controllersModule.js

  3. 按如下方式创建控制器:

    app.controller('skillsController', ['$scope', function($scope){
    $scope.skills = [
        "html",
        "css",
        "js",
        "jquery",
        "angularjs",
        "php",
        "mysql",
        "joomla"
    ];
    }]);
    
  4. 与您的投资组合控制器相同。您希望为控制器使用多少文件并不重要。

    另请参阅:https://docs.angularjs.org/guide/controller

    希望,这有助于......