Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Here is my solution:

MyFactory = ->
  test: -> "test"

class Base
  @$inject: ["MyFactory"]
  constructor: -> return (@MyFactory) => @
  restrict: "E"
  link: (scope, element, attr) =>
    scope.test = @test()

class MyDirective extends Base
  test: -> @MyFactory.test()


angular.module("app", []).factory("MyFactory", MyFactory).directive("myDirective", new MyDirective)

I do feel like it's a little twisted, but could not find anything better, has anyone a better idea?

Sample: http://jsbin.com/eMuPoWU/1/edit?html,js,output

share|improve this question
    
Would you mind posting as javascript? –  Michael Calkins Jan 4 at 1:25

1 Answer 1

up vote 2 down vote accepted
angular.module('auth-service', [
    'base-service'
])

.factory 'AuthService', (BaseService, Restangular) ->

    class AuthService extends BaseService

        constructor: () ->
            super()

        restBase: ->
            Restangular.all('auth')

        singleBase: (options) ->
            Restangular.one('auth', options.entity.id)

        logout: (options)->
            @putSingle(options)

    new AuthService()

This is an example of a way to do a singleton. This is a great gist https://gist.github.com/ProLoser/5645860

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.