Question

My service is:

myApp.service 'userService', [
  '$http'
  '$q'
  '$rootScope'
  '$location'
  ($http, $q, $rootScope, $location) ->
    deferred = $q.defer()

    @initialized = deferred.promise

    @user =
      access: false

    @isAuthenticated = ->
      @user =
        first_name: 'Shamoon'
        last_name: 'Siddiqui'
        email: 'ssiddiqui@liquidnet.com'
        access: 'institution'

      deferred.resolve()
]

And I'm loading it in a .run as follows:

myApp.run [
  '$rootScope'
  'userService'
  ($rootScope, userService) ->

    userService.isAuthenticated().then (response) ->
      if response.data.user
        $rootScope.$broadcast 'login', response.data
      else
        userService.logout()
]

But firebug is telling me:

TypeError: userService.isAuthenticated is not a function
    return userService.isAuthenticated().then(function(response) {

Not sure what I'm doing wrong. Any ideas?

Était-ce utile?

La solution

Your script is compiled to this:

return this.isAuthenticated = function() {
 ...

That means that userService is in fact the isAuthenticated function. Just add a return statement at the end of the userService function.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top