AngularJS: 使用 orderBy 对带空格的字符串进行排序

AngularJS: Sorting Strings With Spaces Using orderBy

我有一个 ng-repeat 正在进行,其中:

<a ng-repeat="contact in contacts | orderBy:'name'">
{{contact.name}}
</a>

我试过谓词:name, -name, name.substr(0, 3)

联系人 'name' 属性 如 "John Smith"、"Betty Ford"、"Hawkeye Pierce" 等

ng-repeat 有效,但 orderBy 无效。

我的字符串可能无法成功排序是否有原因?

1:orderBy 仅适用于数组——参见 http://docs.angularjs.org/api/ng.filter:orderBy

来源:Angular - Can't make ng-repeat orderBy work

你的 'contacts' 是什么?

2 : 尝试

<div ng-repeat="contact in contacts | orderBy:'name'">
<a>{{contact.name}}</a>
</div>

这是适用于您的情况的link

希望对你有所帮助

'http://plnkr.co/edit/EhV5RHszZns5qTHM8qBu?p=preview'