剛開始使用angularJS,我不確定爲什麼我不能使用模塊。不確定爲什麼'userApp'模塊不可用
第一個代碼片段是HTML(main.js)中引用的代碼片段。
'use strict';
angular.module('userApp')
.controller('MainCtrl', function($scope, $http) {
$scope.user = [];
$http.get('http://127.0.0.1:8080/collector/50001366562').success(function(data) {
$scope.user = data;
})
})
<html ng-app="userApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js"></script>
<script src="js/controllers/main.js"></script>
</head>
<body ng-controller="MainCtrl">
{{user}}
</body>
</html>
是否有人可以解釋爲什麼這不工作?
在Chrome JS控制檯我得到以下錯誤:
Uncaught Error: [$injector:nomod] Module 'userApp' 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.
Uncaught Error: [$injector:modulerr] Failed to instantiate module userApp due to: Error: [$injector:nomod] Module 'userApp' 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.
是的,當然可以,否則它是對現有的(以前聲明的)該名稱的模塊的引用 – charlietfl
可以使用全局變量分配控制器W/O,但是您的第一條語句是真實的 –
@ArtemPetrosian是的,您使用你有什麼問題...沒有依賴性參數...'angular.module('userApp').control('AnotherCtrl'...' – charlietfl