2016-07-26 5 views
0

ok 범위 컨트롤러에 문제가 있습니다. 여러 가지 시도를 해봤지만, Angular에서 선언 한 버전 (1.5.8)에서는 작동하지 않습니다. 그래서 여기AngularJS 1.5.8 : Controller & Scope

내 코드의 HTML입니다 :

<body ng-app="myApp"> 



<input type="text" ng-model="query"/> 
<select ng-model="order"> 
    <option value="username">Organiser par nom</option> 
    <option value="content">Organiser par content</option> 
</select> 


<div ng-controller="CommentsCtrl"> 
    <div ng-repeat="comment in comments |filter:{content: query} |orderBy:"> 
     <p> 
       <strong>{{comment.username}}</strong><br> 
       {{comment.content}} 
     </p> 

    </div> 
</div> 

이 내 자바 스크립트입니다 :

<script> 
var myApp = angular.module('myApp',[]); 
myApp.controller('CommentsCtrl', ['$scope', function($scope) { 
    $scope.comments = [ 
{ 
"username": "Goodman", 
"city": "Bonanza", 
"email": "[email protected]", 
"content": "naborum ut. Nisi in ex consequat quis sitet exercitation." 
}, 
{ 
"username": "Holder", 
"city": "Lloyd", 
"email": "[email protected]", 
"content": "naborum ut. Nisi in exunt magna in et exercitation." 
} 
]; 
}]); 
</script> 

그것은 어떤 아이디어 범위를 표시 할 수 없습니다?

+0

컨트롤러에 입력 태그를 넣으십시오. –

답변

0

<div ng-controller="CommentsCtrl">

0

Here is your working code<input type="text" ng-model="query"/>를 이동하려고합니다.

Tilekbekov Yrysbek이 언급했듯이 코드를 이동하고 orderBy 매개 변수를 추가해야합니다. 그래서 최종 HTML 코드는

<body ng-app="myApp"> 

<div ng-controller="CommentsCtrl"> 
<input type="text" ng-model="query"/> 
<select ng-model="order"> 
    <option value="username">Organiser par nom</option> 
    <option value="content">Organiser par content</option> 
</select> 
    <div ng-repeat="comment in comments |filter:{content: query} |orderBy:order"> 
     <p> 
       <strong>{{comment.username}}</strong><br> 
       {{comment.content}} 
     </p> 

    </div> 
</div> 
</body> 
0

있는 OrderBy는 비워 둘 수 없습니다해야 할 것이다. 시험해보십시오

<div ng-repeat="comment in comments |filter:{content: query} |orderBy:order">