2016-12-13 49 views
0

我是新來噶,真的希望瞭解下面的錯誤的原因的任何幫助:需要幫助的建立噶(得到一個錯誤)

Uncaught Error: [$injector:nomod] Module 'myApp.controllers' is not available! 
You either misspelled the module name or forgot to load it. If registering a 
module ensure that you specify the dependencies as the second argument. 

app.js

angular.module('myApp', [ 
    'ngRoute', 
    'myApp.controllers', 
    'myApp.filters', 
    'myApp.services', 
    'myApp.directives' 
]). 
config(function ($routeProvider, $locationProvider) { 

controllers.js

angular.module('myApp.controllers', []); 

StoreCtrl.js

angular.module('myApp.controllers'). 
    controller('StoreCtrl', ['$scope', '$http', function ($scope, $http) { 

StoreCtrl.spec.js

describe('StoreCtrl', function() { 
    beforeEach(module('myApp.controllers')); 

    var $controller; 

    beforeEach(inject(function(_$controller_){ 
     // The injector unwraps the underscores (_) from around the 
     // parameter names when matching 
     $controller = _$controller_; 
    })); 

    describe('$scope.filterByPrice', function() { 
     it('test spec', function() { 

     }); 
    }); 
}); 

karma.conf.js

files: [ 
    'public/js/scripts/angular/angular.js', 
    'public/js/scripts/angular-mocks/angular-mocks.js', 
    'public/js/scripts/angular-route/angular-route.min.js', 
    'public/js/app.js', 
    'public/js/controllers/*.js', 
    'tests/**/*.spec.js' 
], 

文件結構

enter image description here

+0

app.js需要其他文件,所以你需要加載最後一個 – devqon

+0

@ devqon,謝謝你的迴應,但是這並沒有解決我的問題。幸運的是,我找到了這個問題併發布瞭解決方案。 – absingharora

回答

0

噶沒有在StoreCtrl.js前採摘controllers.js文件

我不得不改變代碼如下:

'public/js/controllers/*.js', 

'public/js/controllers/controllers.js', 
'public/js/controllers/StoreCtrl.js', 

它現在的作品:)