Skip to content

Extending a Service

Joshua Nussbaum edited this page Feb 10, 2015 · 1 revision

You can add functionality to a service without copying all the code, by using angular.extend().

Here's an example of extending the Catalog service

.factory 'CatalogExt', ($http, Catalog) ->

    extended = angular.extend(Catalog, {})
    extended.doSomethingAwesome = ->
        # ...
    
    extended

And then in your controller, take the extended service as a dependency:

.controller 'CustomCtrl', ($scope, CatalogExt) ->
   # ...

Clone this wiki locally