ngRoute 작동하지만 뷰에 모델을 표시 할 수 없습니다. 컨트롤러가 올바르게 감지되지 않은 것으로 보입니다. 이 예제를 실행할 때 아래 결과가 나타납니다. 먼저 사용자 : 이름 : {{user.username}} 평가 :ngroute 작동하지만 컨트롤러가 작동하지 않습니다.
/* file user.js*/
var app= angular.module('userApp',['ngRoute']);
app.controller('userListController', function($scope){
$scope.users=[
\t {
\t "username": "Bryant",
\t "rating": 37
\t },
\t {
\t "username": "Wells",
\t "rating": 1
\t },
\t {
\t "username": "Sims",
\t "rating": 4
\t },
\t {
\t "username": "Blankenship",
\t "rating": 37
\t },
\t {
\t "username": "Simon",
\t "rating": 11
\t },
\t {
\t "username": "Reyes",
\t "rating": 9
\t },
\t {
\t "username": "Malone",
\t "rating": 17
\t },
\t {
\t "username": "Evans",
\t "rating": 25
\t },
\t {
\t "username": "Keller",
\t "rating": 32
\t }
];
});
app.config(function($routeProvider){
$routeProvider.when('/', {templateUrl: '/home.html'}).when('/members', {templateUrl: '/members.html',controller:'userListController'}).otherwise({redirectTo : '/'});
});
<!--file mermbers.html -->
<ul>
<li ng-repeat="user in users"> First user :
<ul>
\t <li> username: {{ user.username }}</li>
\t <li>rating :{{ user.rating }}</li>
</ul>
</li>
</ul>
<!-- file index.html-->
<!doctype html>
<html ng-app="userApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="https://code.angularjs.org/1.5.8/angular-route.min.js"></script>
<script src="user.js"></script>
</head>
<body ng-app="userApp">
<div ng-view></div>
</body>
</html>
이러한 출력은 응용 프로그램의 치명적인 오류가 발생한 경우 일반적입니다. 콘솔 로그 란 무엇입니까? –
Btw, 이것을 확인하십시오. 나는 코드를 plunker에 넣고 root에서 멤버보기를 보여주기 위해 그것을 수정했다. 그것은 다소 작동합니다. 그래서 컨트롤러는 괜찮습니다. [plunker demo] (https://plnkr.co/edit/1eVJxGNle53fs4ebU5Ag?p=preview) –
감사합니다. vladimir, 내 콘솔에 오류가 표시되지 않습니다. 문제가 있음을 발견하지 못했습니다. – midy62