在Firefox $插值误差 [英] $interpolation error in FireFox

查看:159
本文介绍了在Firefox $插值误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的日期出来的数据库看起来像这样的: 2013年11月21日十七时43分20秒

My dates come out of the database looking like this: 2013-11-21 17:43:20

以下code是越野车在FireFox,但在Chrome完美的作品:

The following code is buggy in FireFox but works perfectly in Chrome:

<ul class="job-lookup-results" ng-show="data" style="padding:0 10px;">
    <li class="job-lookup-result" ng-repeat="result in data" style="margin:5px 0; font-size:80%;"><a href="/admin/jobs/edit/{{result.Job.id}}" class="job-lookup-result-link">{{result.Job.name}}</a> ({{result.Job.id}}), {{result.Company.name}}, {{result.Job.created | dateToISO | date:'shortDate'}}</li>
    <li class="job-lookup-result" ng-hide="data.length > 0">No matches found.</li>
</ul>

下面的错误:

[15:17:40.890] "Error: [$interpolate:interr] http://errors.angularjs.org/1.2.5/$interpolate/interr?p0=%20(%7B%7Bresult.Job.id%7D%7D)%2C%20%7B%7Bresult.Company.name%7D%7D%2C%20%7B%7Bresult.Job.created%20%7C%20dateToISO%20%7C%20date%3A'shortDate'%7D%7D&p1=RangeError%3A%20invalid%20date
...

我不明白的错误,但在情况下,它与我的自定义过滤器,在这里它是:

I don't understand the error, but in case it's related to my custom filter, here it is:

app.filter('dateToISO', function() {
  return function(input) {
    input = new Date(input).toISOString();
    return input;
  };
});

更新
当我删除 | dateToISO | 它的工作原理。所以会出现连接到自定义过滤器。

Update When I remove the | dateToISO | it works. So it appears connected to the custom filter.

推荐答案

好吧,因为Firefox是有一个对错误的日期格式配合(铬俯瞰它),你必须手动修复格式。过滤器仍然是要走的路。

Ok, since FireFox is having a fit about the bad date format (Chrome overlooks it), you'll have to manually fix the format. A filter is still the way to go.

标记:

<div>{{Object.created | badDateToISO | date:'shortDate'}}</div>

JavaScript的:

JavaScript:

app.filter('badDateToISO', function() {
  return function(badTime) {
    var goodTime = badTime.replace(/(.+) (.+)/, "$1T$2Z");
    return goodTime;
  };
});

住在这里的演示(点击进入)。

Live demo here (click).

这篇关于在Firefox $插值误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆