简体   繁体   English

我在使用力矩和角度滤镜时遇到问题

[英]I am having issues with moment and angular filters

This worked before the jsfiddle update and now it doesn't work. 这在jsfiddle更新之前有效,但现在不起作用。 Any help would be welcome. 任何帮助都将受到欢迎。

Here is the HTML 这是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>

... and here is the Javascript ...这是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/ https://jsfiddle.net/galnova/tkchx8me/8/

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

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

All you need to do is use the https version of the moment.min.js in your external dependencies for JSFiddle. 您需要做的就是在moment.min.js的外部依赖项中使用moment.min.js的https版本。

If you look in the browser console in your original fiddle, you will see this: 如果您在原始小提琴中的浏览器控制台中查看,将会看到以下内容:

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 '. 混合内容:“ https://fiddle.jshell.net/galnova/tkchx8me/8/show/ ”上的页面已通过HTTPS加载,但请求了不安全的脚本“ 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提供。

So, all you need to do is serve your moment dependency over HTTPS. 因此,您要做的就是通过HTTPS服务您的时刻依赖性。

This is the only change I made to your fiddle: https://jsfiddle.net/w2u6LL6z/ 这是我对您的提琴所做的唯一更改: https : //jsfiddle.net/w2u6LL6z/

Now, it's working! 现在,它正在工作!

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

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