2016-07-26 96 views
0

好的我有一些問題與範圍控制器我已經嘗試了很多不同的東西,但它不適用於我聲明的(1.5.8)Angular版本,AngularJS 1.5.8:控制器和範圍

所以這裏是我的代碼的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> 

,這是我的Java腳本:

<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

嘗試移動<input type="text" ng-model="query"/><div ng-controller="CommentsCtrl">

0

Here is your working code

正如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

排序依據不應該是空的。 試試這個

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