我的服务是:
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()
]
我将其加载到.run
中,如下所示:
myApp.run [
'$rootScope'
'userService'
($rootScope, userService) ->
userService.isAuthenticated().then (response) ->
if response.data.user
$rootScope.$broadcast 'login', response.data
else
userService.logout()
]
但是萤火虫告诉我:
TypeError: userService.isAuthenticated is not a function
return userService.isAuthenticated().then(function(response) {
不确定我做错了什么。有什么想法吗?
答案 0 :(得分:2)
您的脚本编译为:
return this.isAuthenticated = function() {
...
这意味着userService
实际上是isAuthenticated
函数。
只需在return
函数的末尾添加userService
语句。