<div ng-repeat="r in vm.GetRequests() | filter: vm.SearchText | orderBy:['LastName','FirstName']">
上面的行中是否有语法错误,因为当我运行它时它会给我语法异常
未捕获错误:语法错误,无法识别的表达式: div [ng-repeat =&#39; r in vm.GetRequests()| filter:vm.SearchText | ORDERBY:&#39;名字&#39;&#39;姓&#39;]&#39;]
仅在Chrome中出现错误
答案 0 :(得分:2)
您的代码完美无缺,但下面的演示可能会帮助您摆脱这个问题。我还用一种较旧的角度版本进行了测试。
angular.module('testApp', [])
.controller('testCtrl', function($scope) {
var people = [{
FirstName: 'John',
LastName: 'Rambo'
}, {
FirstName: 'John',
LastName: 'Rambo 2'
}, {
FirstName: 'Silvester',
LastName: 'Stallone'
}, {
FirstName: 'Chuck',
LastName: 'Norris'
}
];
$scope.vm = {
SearchText: 'John',
GetRequests: function() {
return people;
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testCtrl">
<div ng-repeat="r in vm.GetRequests() | filter: vm.SearchText | orderBy:['LastName','FirstName']">
{{r.FirstName}} {{r.LastName}}
</div>
</div>