#A: $delegate, replace factory method

by yaero

HTML

<div ng-app='app'>
    <div ng-controller='ctrl'>
        message: <b>{{ system.message }}</b>
    </div>
</div>

JavaScript

angular.module('app', [])
.controller('ctrl', function($scope, systemMessage) {
   $scope.system = new systemMessage();
})
.factory('systemMessage', function() {
    return function () {
        this.error = 'Some system message'
    }
}).config(function($provide) {
    $provide.decorator('systemMessage', function($q, $delegate) {
return $q.when(true).then(() => {
		console.log('hey');
    			Object.defineProperty($delegate.prototype, 'message', {
                    get: function() {
                        return this.error.toUpperCase()
                    }
                });
                return $delegate;

    })
      
        
    });
    
});