好吧我对示波器控制器有一些问题我尝试了很多不同的东西,但它不适用于我声明的Angular版本(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": "goodmanalston@helixo.com",
"content": "naborum ut. Nisi in ex consequat quis sitet exercitation."
},
{
"username": "Holder",
"city": "Lloyd",
"email": "holderalston@helixo.com",
"content": "naborum ut. Nisi in exunt magna in et exercitation."
}
];
}]);
</script>
它无法显示任何想法的范围?
答案 0 :(得分:0)
尝试将<input type="text" ng-model="query"/>
移至<div ng-controller="CommentsCtrl">
答案 1 :(得分:0)
正如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>