首页 > Web开发 > 详细

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

时间:2015-01-07 12:36:27      阅读:1300      评论:0      收藏:0      [点我收藏+]

<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>

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

原文:http://www.cnblogs.com/mcat/p/4208036.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!