0

I started my first angular application, and am running into an issue where my "home" module isn't working because of a dependency issue. I don't see any dependency missing that I would need. I am using $stateProvider, and $urlProvider, but I am injecting that into the configuration for the home module, so I'm not sure where the problem would lie ?

Config.$inject = ["$stateProvider", "$urlRouterProvider"];
angular.module('home', []).config(Config)

function Config($stateProvider, $urlRouterProvider){
    $stateProvider
    .state('home', {
        url: '/login',
        templateUrl: './views/login.html'
    })
}

angular.module('home').controller('loginCtrl', function($scope){
    $scope.helloWorld = function(){
        console.log("This works!")
    }
})

The consoled error:

[$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=home&p1=Error%3A%20…
0

1 Answer 1

3

Since "$stateProvider" and "$urlRouterProvider" providers are not part of the core AngularJS module, you need to inject modules, that have this provides into your home module definition. As far as I know, $stateProvider is from ui router module, so

angular.module('home', ['ui.router']).
...

Keep in mind that you also need to include this Javascript in your HTML file. It is in the angular-ui-router file

<script src="js/angular-ui-router.min.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome, I injected ui.router into my module and included the script, and now it works. So Angular services and providers aren't global pieces of code you can just use anywhere, your module has to depend on the module that has those services or providers, unless they are part of the core AngularJS module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.