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>
<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>
相关文章推荐
- Dubbo学习总结(1)——Dubbo入门基础与实例讲解
- Node.js基础入门实例讲解
- MySql入门教程mysql基础知识学习实例讲解
- Dubbo学习总结(1)——Dubbo入门基础与实例讲解
- Dubbo学习总结(1)——Dubbo入门基础与实例讲解
- Dubbo入门基础与实例讲解
- Dubbo入门基础与实例讲解
- spark入门知识讲解和基础数据操作编程(统一用scala编程实例)
- Node.js基础入门实例讲解
- Dubbo入门基础与实例讲解(转)
- AngularJS基础讲解-语法入门01
- AngularJS基础讲解-语法入门02
- Dubbo入门基础与实例讲解
- unity经典入门课程之C#基础实例讲解(打砖块实例)
- AngularJS入门教程之 XMLHttpRequest实例讲解
- Node.js基础入门实例讲解
- Node.js基础入门实例讲解
- Linux入职基础-7.4_Makefile文件使用入门很简单(实例讲解)
- 实例讲解如何通过Oracle成功发送邮件-入门基础
- Dubbo(1)——入门基础与实例讲解