angularjs decorator 装饰器

services.js

.service('emailService', function() {

this.email = "give me!";

this.setContent = function(content) {

this.email = content;

};

this.send = function(recipient) {

return 'sending "' + this.email + '" to ' + recipient;

};

})

app.js

.config(function($provide){

$provide.decorator('emailService',function($delegate){

$delegate.sendWithSignature=function(recipient,email){

return 'sending "'+this.email+'" to '+recipient+" by "+email

}

return $delegate

})

})

controller.js

$scope.resole = emailService.sendWithSignature("lin", "how are you !");

alert($scope.resole);

猜你喜欢

转载自blog.csdn.net/qq_41687724/article/details/82146593
今日推荐