我在使用 moment 和 angular 过滤器时遇到问题

I am having issues with moment and angular filters

这在 jsfiddle 更新之前有效,现在无效。欢迎任何帮助。

这是HTML

<div ng-app="app" ng-controller="ctrl">

    {{ date | date: 'MM-dd-yy' }} <br/> <br/>

    {{ date | date: 'MMM-dd-yyyy' }} <br/> <br/>

    {{ date | date: 'MMMM-dd-yyyy' }} <br/> <br/>

    {{ d | date: 'MM/dd/yy' }} <br/> <br/>

    {{ d | date: 'MMM/dd/yyyy' }}

</div>

... 这是 Javascript

var app = angular.module("app", []);
app.constant("moment", moment);

app.controller("ctrl", function($scope, moment) {
    $scope.d = new Date();
    $scope.date = new moment();
    $scope.getRandomDate = function(){
        var year = Math.floor(Math.random() * 2) + 2014;
        var month = Math.floor(Math.random() * 12) ;
        var day = Math.floor(Math.random() * 31);
        return moment([year, month, day]).toDate();
   };
   $scope.date = $scope.getRandomDate(); 

});

https://jsfiddle.net/galnova/tkchx8me/8/

将模块 angularMoment 添加为应用程序模块的依赖项

var app = angular.module('app', ['angularMoment']);

您需要做的就是在 JSFiddle 的外部依赖项中使用 https 版本的 moment.min.js

如果您查看原始 fiddle 中的浏览器控制台,您将看到:

Mixed Content: The page at 'https://fiddle.jshell.net/galnova/tkchx8me/8/show/' was loaded over HTTPS, but requested an insecure script 'http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.6.0/moment.min.js'. This request has been blocked; the content must be served over HTTPS.

因此,您需要做的就是通过 HTTPS 服务您的时刻依赖。

这是我对您的 fiddle 所做的唯一更改:https://jsfiddle.net/w2u6LL6z/

现在,它开始工作了!