2
我試圖擴展服務提供商;更具體地說$ routeProvider從ngRoute模塊擴展服務提供商(提供商)
我伸出提供商是這樣的:
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;
}
}
路由的配置看起來是這樣的:
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: '/'
});
}
我讀過這個線程:
但他們Ø只是談論擴展「工廠」 - 服務
有人可以解釋這裏發生了什麼?非常感謝幫助。