Decorator Example

This is the Example for the Decorator Example

by DineshAngappa

HTML

<div ng-app="mainApp">
  <div ng-controller="mainCtrl">

    <p>
      {{content}}
    </p>

  </div>


</div>

JavaScript

angular.module('mainApp', ['childApp'])
.controller('mainCtrl', ['$scope', 'myService',  function($scope, myService){
myService.setContent('James Bond');



$scope.content = myService.sendWithSignature('[email protected]','X4u');

}])
.decorator("myService", function myServiceDecorator($delegate){

 $delegate.sendWithSignature = function(email, sign){
   return 'Hello Sending to '+ this.name + ' at '+ email + ' with Signature '+ sign;
 
 }
 
 return $delegate;

});

angular.module('childApp', [])
.service('myService', function(){
 var that = this;
 that.name = '';
 
 that.setContent = function(name){
   that.name = name;
 
 }
 
 that.sendMail = function(email){
  return 'Hello Sending to '+ that.name + ' at '+ email;
 }
 
 return that;
});