Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: How to get $routeProvider after app.config

Tags:

angularjs

I am trying to access $routeProvider in one of my controller in order to add a route. How do I do that?

function Cont($scope,$routeProvider) {

};

This doesn't work for me; I am getting: Error: Unknown provider: $routeProviderProvider <- $routeProvider

like image 554
ciochPep Avatar asked Feb 20 '13 15:02

ciochPep


2 Answers

$routeProvider and other providers can only be injected to a modules config block. What is it that you want to do with the $routeProvider inside a controller?

like image 179
Anders Ekdahl Avatar answered Nov 23 '22 22:11

Anders Ekdahl


In the controller, $route is accessible but $routeProvider is not. Maybe you can just copy the function out, for example, the '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 routes definition in Angular.js?

like image 26
SetupX Avatar answered Nov 24 '22 00:11

SetupX