AngularJS scope bug? Different results on chrome(43) and firefox(38.0.5)

I was fiddling around with angularjs recently and I discovered something weird.

Using a function to determine a date difference between dates stored in properties of an object inside ng-repeat I got different results on chrome and different on firefox

PLUNKER
result from firefox: http://scr.hu/28dp/17r4y (incorrect)
result from chrome: http://scr.hu/28dp/uik13 (correct)

Function I use to calculate time difference :

$scope.daysDiff = function (date) {
        var dateobj = new Date(date);
        var current = new Date("2015-06-28");
        var resultDays = Math.floor(Math.abs((current - dateobj) / (86400000))); //1k *60*60*24
        return  resultDays;
    };

I use it several times within ng-repeat to show or hide elements like so:

<tr ng-repeat="dat in data">
  ...
  <td><div class="inline" ng-show="daysDiff(dat.dateExpires) < 14">YES</div></td>
  ...
  <td><div class="inline" ng-show="daysDiff(dat.dateUpdate) < 14">YES</div></td>
  ...
</tr>

exactly the same behavior when using ng-if

//edit

This question isn't about generating the proper table with angular, its about inconsistency between chrome and firefox.

The problem remains that the expressions are not evaluated properly in firefox for some reason. You can see it in the plunker example that I've attached above. Try opening it in chrome and then in firefox.

//edit #2 added td tags for clarity

note: The same issue happens in angular 1.3


The problem was with the Date() object itself.. chrome was able to parse a date 2015-07- 7 without any issues whereas firefox returned an invalid date object. with 2015-07-07 works fine.

working example http://plnkr.co/edit/MnhLCohlWB3Nrc2QQ2Zi?p=preview

dateExpires: "2015-07-" + ((i<3) ? ("0"+(i + 7)) : (i + 7)), 

which simply added the 0 before the day number

链接地址: http://www.djcxy.com/p/96282.html

上一篇: JavaScript提升和功能范围之间的混淆

下一篇: AngularJS范围错误? 铬(43)和火狐(38.0.5)