Decorator -- AngularJS
References:
1. http://docs.angularjs.org/api/AUTO.$provide#constant
2. https://groups.google.com/forum/#!searchin/angular/decorator/angular/72ukcZYeWGE/aMwTXCkKw1QJ
剛好在看$provide.decorator在做什麼,然後在AngularJS的官方mail list中有人討論看到範例就記錄下來以防自己忘記(請參考*2)。
1. http://docs.angularjs.org/api/AUTO.$provide#constant
2. https://groups.google.com/forum/#!searchin/angular/decorator/angular/72ukcZYeWGE/aMwTXCkKw1QJ
剛好在看$provide.decorator在做什麼,然後在AngularJS的官方mail list中有人討論看到範例就記錄下來以防自己忘記(請參考*2)。
If you want to decorate $http:
ng.config(function ($provide) {
$provide.decorator('$http', function ($http) {
// decorate $http
return $http;
});
});
If you want to "extend it" (create a new service which prototypally inherits from $http):
myApp.factory('myHttp', function ($http) {
myHttp = function() {}
myHttp.prototype = new $http();
// add other methods
return myHttp
});
留言