一直在AngularJS上工作,但我收到一個錯誤,指出Angular在被定義之前被使用。我觀看了一些視頻並閱讀了文檔。即使只是在js文件的第一行,我得到的錯誤。在索引文件中,我將angular 1.6.2作爲第一個文件之前的任何其他內容調用,這就是爲什麼我被困在爲什麼被告知在被定義之前使用它的原因。角度在定義之前使用
我的HTML是:
<!doctype html>
<html ng-app="weatherApp">
<head>
<!-- Bootstrap 3 Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- AngularJS -->
<script src="//code.angularjs.org/1.6.2/angular.min.js"></script>
<script src="//code.angularjs.org/1.6.2/angular-route.min.js"></script>
<script src="//code.angularjs.org/1.6.2/angular-resource.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>Hello, world!</h1>
<div class="container">
<div>
<div id="web-api">
<h1>test</h1>
</div>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</body>
</html>
和JS是:
// MODULE - WEATHER
var weatherApp = angular.module('weatherApp', ['ngRoute', 'ngResource']);
weatherApp.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
// ROUTING
weatherApp.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'home.htm',
controller: 'homeController'
})
});
weatherApp.controller('homeController', ['$scope', function($scope) {
}]);
weatherApp.controller('forecastController', ['$scope', function($scope) {
}]);
我不確定它是否可以幫助,但是您是否嘗試將'ng-app'從'html'移動到'body'標籤? – Arkej
你有沒有嘗試在你的'app.js'包括頭部而不是頭部? – UnholySheep
在'angular.js'文件之前加載'angular-resource'和'angular-route'。將角度文件移動到jquery下面,這樣就可以在角度文件中使用jquey屬性 – nivas