2016-11-15 2 views
0

Я новый в 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> 

in chrome Я получил ошибку Argument 'artistController' is not aNaNunction, got undefined

Есть идеи? Благодаря Регард

+0

Похоже, что вы должны повесить свой ArtistController с вашего модуля приложения. Вы как бы просто объявили его открытым на своем собственном, поэтому его не обнаруживают в вашем модуле ng-app (это «приложение»). –

ответ

0

Предположив вы не делаете другие ошибки, вам необходимо изменить свой контроллер:

angular.module('app') //if you do var app = ..., you can also do app.controller 
     .controller('ListController', ListController); 

ListController.$inject = [ "$scope", "$http" ]; 

function ListController($scope, $http){ 
    $http.get('file:///C:/wamp/www/angular - copy/data.json').success(function (data) { 
    $scope.artists = data; 
    }); 
} 

Взгляните на AngularJS Documentation on Controllers.

+0

Я добавляю ваш код в приложение, но все еще не работаю. не могли бы вы мне помочь? спасибо –

+0

Вам также нужно удалить artistController из зависимостей приложений – AndreaM16