我是AngularJS中的新成員 我編寫了一個有錯誤的應用程序,不會顯示整個代碼。那些有角碼的代碼部分沒有出現。錯誤:ng:areq在AngularJS中未定義的錯誤參數和參數
MAIN.js文件
var app = angular.module('app', [
'ngRoute',
'artistController'
]);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/list' , {
templateUrl: 'list/list.html',
controller: 'artistController'
}).otherwise({
redirectTo: '/list'
});
}]);
var artistController = angular.module('artistController' , []);
artistController.controller("ListController", [
"$scope", "$http" ,function ($scope , $http) {
$http.get('file:///C:/wamp/www/angular - copy/data.json').success(function (data) {
$scope.artists = data;
});
}
]);
的index.html
<!DOCTYPE html>
<html ng-app="app">
<head>
<meta charset="utf-8">
<title>angular</title>
<link rel="stylesheet" href="file:///C:/wamp/www/angular/bootstrap-3.3.7- dist/css/bootstrap.min.css" media="screen" title="no title">
<link rel="stylesheet" href="file:///C:/wamp/www/angular - copy/main.css" media="screen" title="no title">
<script src="file:///C:/wamp/www/angular/angular-1.5.8/angular.min.js" charset="utf-8"></script>
<script src="file:///C:/wamp/www/angular/angular-1.5.8/angular-route.min.js" charset="utf-8"></script>
<script src="file:///C:/wamp/www/angular - copy/main.js" charset="utf-8"> </script>
</head>
<body>
<div class="containor" ng-view></div>
</body>
</html>
list.html
<div>
<h2>Search directory</h2>
<label>Search:</label>
<input placeholder="Search for your person" autofocus="" ng-model="query"> </input>
<label>By:
<select ng-model="artistOrder">
<option value="lastName">lastName</option>
<option value="firstName">firstName</option>
</select>
</label>
</div>
<ul class="background" ng-controller="ListController">
<li class="center" ng-repeat="x in artists | filter:query | orderBy:artistOrder">
<img src="img.png" alt="photo" />
<h1 class="col-lg-4">{{ x.firstName | uppercase }}</h1>
<h2 class="col-lg-5">{{ x.lastName }}</h2>
</li>
</ul>
</section>
在鉻我得到了一個錯誤Argument 'artistController' is not aNaNunction, got undefined
任何想法? 感謝看待
看起來你應該把你的artistController掛在你的app模塊之外。你只是自己公開宣佈它,所以它不會在你的ng-app模塊(即「app」)中找到。 –