Six stars of AngularJS - Part 3

// sample 1
app.factory('movieService', movieService);

    function movieService() {
        return {
            getAllMovies: getAllMovies
        }

        function getAllMovies() {
            return ['engMovie1', 'engMovie2', 'engMovie3'];
        }
    }
// sample 2
 app.config(function($provide) {
        $provide.decorator('movieService', movieServiceDecorator);

        function movieServiceDecorator($delegate) {
            var originalGetAllMovies = $delegate.getAllMovies;
            
            $delegate.getAllMovies = function() {
                var result = originalGetAllMovies();
                return result.slice(0,2);
            }

            return $delegate;

        }
    });
comments powered by Disqus