您的位置:首页 > Web前端 > AngularJS

AngularJS入门基础——$provide.decorator 实例讲解

2015-01-07 11:43 791 查看
<body ng-controller="OneController">

<script>
var Foobar = function() {
return {
"name": "lin"
}
};
angular.module('myApp', [])
.controller('OneController', function($scope, emailService) {
$scope.resole = emailService.sendWithSignature("lin", "how are you !");
alert($scope.resole);
})
.service('emailService', function() {
this.email = "give me!";

this.setContent = function(content) {
this.email = content;
};

this.send = function(recipient) {
return 'sending "' + this.email + '" to ' + recipient;
};
})
.config(function($provide) {
$provide.decorator('emailService', function($delegate) {
$delegate.sendWithSignature = function(recipient, signature) {
return 'sending "' + this.email + '" to ' + recipient + " by " + signature;
};
return $delegate;
});
});

</script>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: