如何在角度视图中获得完整的momentjs api? [英] how to get full momentjs api inside angular view?
问题描述
使用 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屋!