如何在角度视图中获得完整的momentjs api? [英] how to get full momentjs api inside angular view?

查看:18
本文介绍了如何在角度视图中获得完整的momentjs api?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 angular 时在视图中获取 moment() 对象的首选方法是什么?

What's the preferred method of getting a moment() object inside a view when using angular?

貌似有这个项目,但看起来维护得不好.

It looks like there is this project, but it does not look well maintained.

https://github.com/gdi2290/angular-momentjs

推荐答案

还有一个比较流行的 angular-moment 项目... https://github.com/urish/angular-moment

There is a more popular angular-moment project... https://github.com/urish/angular-moment

有了它,你可以像这样注入瞬间......

With it, you can inject moment like this...

app.controller("ctrl", function($scope, moment) {
    $scope.date = new moment();
});

小提琴

或者,如果您不需要 angular-moment 提供的附加功能和指令,您可以使用 angular.value()angular.constant 在您的应用程序中注入 momentjs() (angular-moment 在内部使用 constant() 来做到这一点)...

Or if you don't need the additional functionality and directives provided by angular-moment, you can make momentjs injectable in your app by using angular.value() or angular.constant() (angular-moment uses constant() internally to do this)...

app.constant("moment", moment);

app.controller("ctrl", function($scope, moment) {
    $scope.date = new moment();
});

小提琴

这篇关于如何在角度视图中获得完整的momentjs api?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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