简体   繁体   English

AngularJS ng-repeat在Chrome中不起作用

[英]AngularJS ng-repeat doesn work in Chrome

I know this question was asked already multiple times and may be considered as duplicate. 我知道这个问题已经被问过多次了,可以认为是重复的。 But I did not find an answer and decided to create new question. 但是我没有找到答案,因此决定提出一个新问题。

The problem is ng-repeat doesn't work correct in Chrome, while it works fine in FF. 问题是ng-repeat在Chrome中无法正常运行,而在FF中则可以正常工作。 There were couple suggestion in order to fix that but I already using them and it doesn't help. 为了解决这个问题,有一些建议,但是我已经在使用它们了,没有帮助。

  1. One of the suggestions was to use array as a model in instead of object. 建议之一是使用数组代替对象作为模型。 2. The second one was to use single quoted literal in order by. 2.第二个是按顺序使用单引号文字。

I met both conditions and still see the problem in Chrome. 我同时满足这两个条件,但仍然在Chrome中看到了问题。

Here is my code: 这是我的代码:

<a  ng-click="pred = 'price'; reverse=!reverse">
    <span></span>
</a> | 
<a ng-click="pred = 'name'; reverse=!reverse">
    <span></span>
</a> | 
<a ng-click="pred = 'time'; reverse=!reverse">
    <span></span>
</a>
<div ng-repeat="item in items | orderBy:pred:!reverse">
</div>

Also there is link you can open in two browsers. 另外,还有可以在两个浏览器中打开的链接。 There are items that are sorted by time (left column) they are sorted in FF but not in Chrome. 有些项目按时间排序(左列),它们以FF排序,而不是Chrome。

I am using angular 1.2.9 I think. 我认为我使用的是角1.2.9。 Please advice how to solve that. 请建议如何解决。

Reason might be you did not initialized reverse variable. 原因可能是您没有初始化反向变量。

 (function(angular) { 'use strict'; angular.module('orderByExample1', []) .controller('ExampleController', ['$scope', function($scope) { $scope.friends = [ {name: 'John', phone: '555-1212', age: 10}, {name: 'Mary', phone: '555-9876', age: 19}, {name: 'Mike', phone: '555-4321', age: 21}, {name: 'Adam', phone: '555-5678', age: 35}, {name: 'Julie', phone: '555-8765', age: 29} ]; }]); })(window.angular); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body ng-app="orderByExample1"> <div ng-controller="ExampleController" ng-init='reverse=false;'> <a ng-click="pred = 'name'; reverse=!reverse"> Name </a> | <a ng-click="pred = 'phone'; reverse=!reverse"> Phone </a> | <a ng-click="pred = 'age'; reverse=!reverse"> Age </a> <table class="friends"> <tr> <th>Name</th> <th>Phone Number</th> <th>Age</th> </tr> <tr ng-repeat="friend in friends | orderBy:pred:reverse"> <td>{{friend.name}}</td> <td>{{friend.phone}}</td> <td>{{friend.age}}</td> </tr> </table> </div> </body> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM