Issue
I am trying to use moment.js and moment-timezone-with-data.js in my application to display the dates in any timezone.
I have included the cdn for both of these js files in my index.html and added moment as required in my controller.
It gives -
Error: [$injector:unpr] http://errors.angularjs.org/1.5.7/$injector/unpr?p0=momentProvider%20%3C-%20moment%20%3C-%20manageScheduleController
My Code:
index.html - cdn for both these js files.
Controller:
.controller('manageScheduleController', function($http,$scope,sessiontracker,
$window,$filter, $dialogs, Upload, $timeout,moment)
Solution
moment-timezone-with-data is Javascript library on the top of momentjs. You can directly use it inside angular application by just using moment variable. (You could consider creating wrapper constant for the same so that you can mock at the time of testing the same).
There you don't need to inject moment inside controller factory function as dependency. Removing moment parameter from controller function will fix the problem.
Note: Make sure you had reference
moment-timezone-with-data.json yourindex.htmlpage.
Answered By - Pankaj Parkar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.