2016-08-17 149 views
2

我得到每當我試圖用require.js

我bower.json文件注入依賴的角度模塊錯誤:

{ 
"name": "asa", 
"version": "1.0", 
"authors": [ 
"asda" 
], 
"description": "aaaa", 
"dependencies": { 
"angular": "1.3.8", 
"angular-route": "1.3.8", 
"requirejs": "2.1.15", 
}, 
"license": "sss", 
"homepage": "index.html", 
"ignore": [ 
"**/.*", 
"node_modules", 
"bower_components", 
"src/main/webapp/resources/bower_components", 
"test", 
"tests" 
] 
} 


Main.js

var app = angular.module('myApp', ['route']); 
app.service('abc', function() { 
//some content 
}); 
app.service('def', function($http, $q) { 
//some content 
}); 
var zzz = app.controller('zzz', function ($scope, $http, $filter, abc, def) { 
//controller content 
}); 
zzz.$inject = ['$scope', '$filter','abc','def']; 



包含依賴我的數據,主文件:主di.js

require.config({ 
paths: { 
    angular: '../lib/dependencies/bower_components/angular/angular', 
    route: '../lib/dependencies/bower_components/angular-route/angular-route', 
    myApp: "person" 
}, 
shim: { 
    angular: { 
     exports: "angular" 
    }, 
    route: { 
     deps: ['angular'] 
    }, 
    myApp: { 
     deps: [ 'angular', 'route'] 
    } 
} 
}); 
require(['myApp'], function() { 

angular.bootstrap(document.getElementById('myApp'), ['myApp']); 

}); 



上運行的應用我碰到下面的錯誤 -
錯誤:

TypeError: e is undefined 
...a("$ngControllerController",f));w(a)}}}n=e.module("ngRoute", ["ng"]).provider("$r... 



Error: [$injector:modulerr] Failed to instantiate module myApp due to: 
[$injector:nomod] Module 'myApp' 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. 
http://errors.angularjs.org/1.3.8/$injector/nomod?p0=myApp minErr/<@http://localhost:8080/AngularJsInJava/lib/dependencies/bower_components/angular/angular.js:63:12 




任何人可以幫我,爲什麼我收到此錯誤?

+0

這可能是由於縮小。在控制器中使用內聯數組符號表示依賴性。請查閱文檔獲取更多詳細信息。https://code.angularjs.org/1.3.19/docs/guide/di –

+0

不熟悉require.js,但在'zzz中。$ inject = ['$ scope','$ filter ','abc','def'];'不應該包含$ http? – Marko

+0

@MarkoMets - 我添加了$ http,但它仍然不能解決我的問題 **錯誤:[$ injector:modulerr]無法實例化模塊myApp ** –

回答

1

這不是定義控制器的正確方法。

var zzz = app.controller('zzz', function ($scope, $http, $filter, abc, def) { 
//controller content 
}); 

創建控制器這樣..

app.controller('zzz', ZzzCtrl); 
ZzzCtrl.$inject = ['$scope', '$filter','abc','def']; 
function ZzzCtrl ($scope, $filter, abc, def) { 
    // controller code here 
} 

此外,如果你使用的縮小你的角碼,你應該總是使用註釋或「$注入」 S。不適用於控制器。 例如。

angular.module('someModule').service('someService',['$someInjection', function($someInjection){}]) 
+0

謝謝Rafael ... !! –

相關問題