Patrick McDermott
Patrick McDermott

Reputation: 1220

Injecting dependency angularMoment returning error

I'm trying to access moment.js API, injecting angularMoment as a dependency into my module but it's returning error:

Error: [$injector:unpr] http://errors.angularjs.org/1.6.4/$injector/unpr?p0=momentProvider%20%3C-%20moment%20%3C-%20transCtrl

I'm following the docs provided by https://github.com/urish/angular-moment but an error keeps being returned. Any idea why?


<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-moment/1.0.1/angular-moment.min.js"></script>
<script src="scripts/app.js"></script>

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

app.controller('transCtrl', ['moment', function(moment){

    $scope.date = new moment();  

}]);

Upvotes: 1

Views: 278

Answers (2)

Alon Eitan
Alon Eitan

Reputation: 12025

Well, after you included the moment.js script before angular-moment.min.js as I suggested in the comments to your question - You now have a simple error in your controller:

app.controller('transCtrl', ['$scope', 'moment', function($scope, moment){

You just need to inject $scope into your controller.

Upvotes: 1

Kumar Nitesh
Kumar Nitesh

Reputation: 1652

Here is the detail on how to use angular-moment

https://github.com/urish/angular-moment

You have to include both moment.js and angular-moment.js in your application.

Upvotes: 1

Related Questions