如何在角度视图中获取完整的moment.js 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();
});
这篇关于如何在角度视图中获取完整的moment.js API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!