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
$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?
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With