Angular: How to get $ routeProvider after app.config

I am trying to access $ routeProvider in one of my controllers to add a route. How to do it?

function Cont($scope,$routeProvider) {

};

This does not work for me; I get:Error: Unknown provider: $routeProviderProvider <- $routeProvider

+5
source share
2 answers

$ routeProvider and other providers can only be entered in the module configuration block. What do you want to do with $ routeProvider inside the controller?

+6
source

$ Route is available in the controller, but $ routeProvider is not. Perhaps you can just copy the function, for example, "when" and "pathRegExp"

See jsfiddle: http://jsfiddle.net/5FUQa/1/

  function addRoute(path, route) {
     //slightly modified 'when' function in angular-route.js
  }
  addRoute('/dynamic', {
    templateUrl: 'dynamic.tpl.html'
  });

Also see: How to defer route determination in Angular.js?

+1
source

All Articles