Unknown provider: $ stateProviderProvider <- $ stateProvider

.controller('myCtrl', function($scope,$localstorage,$stateProvider, $urlRouterProvider) {

  $scope.getNews= function(){
  $stateProvider.stat('app.news')
}

});

Why am I getting an unknown provider error? I have already entered dependecy in my controller.

+4
source share
1 answer

You do what you try to add $ stateProvider to the controller, and not to your app.config () function. If you look at the UI-Router docs, you will see that you have to configure it in app.config, which will load before your controller starts.

You can read data from the $ state provider in your controller, but only when you use it as a service. This may be a confusing difference. I will try to explain below.

Angular : , . , , : AngularJS: vs factory

, , app config(). . , $stateProvider config(), .

, : $stateProvider , Angular , $stateProvider, config(). , , . , $stateProvider $state. , $get, : https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection

, , :

myApp.config(function($stateProvider, $urlRouterProvider) { ... })

, :

myApp.controller('myCtrl', function($state) { ... })
+8

All Articles