mardi 2 décembre 2014

Extending a service provider (provider)


Vote count:

0




I'm trying to extend a service provider; more specifically $routeProvider from the ngRoute module


my extended provider looks like this:



angular
.module('myapp')
.provider('customRoute', customRoute)

function customRoute($routeProvider) {

var extendedProvider = angular.extend({}, $routeProvider, {
// Customization here
});

// These will print almost identical objects
console.log(extendedProvider);
console.log($routeProvider);

this.$get = function() {
return extendedProvider;
}
}


The config of the routes looks something like this:



angular
.module('myapp')
.config(Routes);

function Routes(customRouteProvider, $routeProvider) {

/* This will print an object that looks the same as
the ones printed in the provider definition */
console.log($routeProvider);

/* This object does not look like the $routeProvider any more :( */
console.log(customRouteProvider);

customRouteProvider
.when('/', {
templateUrl: 'path/to/some/template.html',
controller: 'SomeController',
})
.otherwise({
redirectTo: '/'
});
}


I've read this thread:


how can i extend a service


But they only talk about extending the "factory"-service


Can someone explain what is happening here? Help is much appreciated.



asked 3 mins ago







Extending a service provider (provider)

Aucun commentaire:

Enregistrer un commentaire