我想从指令控制器调用服务功能。服务名称为 Auth ,功能名称为 Auth.logout 。我已经在指令的控制器中注入了服务但没有工作。请让我知道我该怎么办?该脚本是用coffeescript编写的。
指令代码: -
class GlobalNav extends BaseDirective
@register 'globalNav', ->
restrict: "E"
templateUrl: 'templates/Directives/global-nav.jade'
controller: ($scope, $ionicSideMenuDelegate, $ionicPopup,Auth) ->
$scope.closeSideMenu = ->
$ionicSideMenuDelegate.toggleLeft(false)
$scope.showConfirm = ->
confirmPopup = $ionicPopup.confirm(
title: 'Message'
template: 'Are you sure you want to logout?')
confirmPopup.then (res) ->
if res
Auth.logout <<<<<<<<<<<<<<<<<<<<< This is not called
return
return
验证服务代码: -
class Auth extends BaseService
@register 'Auth'
AUTH_KEY: 'userAuth'
AUTH_REJECTION: 'authentication'
constructor: (@$q, @$http, @$rootScope, @$cordovaFacebook, @storage, @Api, @$track, @FacebookAuth) ->
authenticated: -> !_.isEmpty(@_getAuth())
logout: ->
q = @$q.defer()
@storage.clearAll()
@_auth = null
@Api.expireGlobalCache()
@$cordovaFacebook.logout().then(q.resolve)
q.promise
答案 0 :(得分:1)
转换为JavaScript后,结果是您没有致电for job in fetch.getJobStats():
if job['userName']+"_"+job['tenantId'] in summaryTotal:
summary = summaryTotal[job['userName']+"_"+job['tenantId']]
else:
summary = Summary(job['userName'], job['tenantId'])
summaryTotal[summary.user+"_"+summary.tenant] = summary
summary.jobs.append(Job(job['jobId'], job['jobStatus'], int(job['fileSize'])))
totalBw += int(job['fileSize'])
print("Cumulative Size: " + str(totalBw))
for summaryKey in summaryTotal.keys():
summary = summaryTotal[summaryKey]
inprogress = []
failed = []
completed = []
cancelled = []
totalBwTenantUser = 0
for job in summary.jobs:
totalBwTenantUser += job.filesize
if job.status == "JOBCANCELLED":
cancelled.append(job.id)
elif job.status == "JOBCOMPLETED":
completed.append(job.id)
elif job.status == "INPROGRESS":
completed.append(job.id)
elif job.status == "JOBFAILED":
completed.append(job.id)
print("-" * 50)
print("Tenant: " + summary.tenant)
print("User : " + summary.user)
print("Size : " + str(totalBwTenantUser))
print("\n")
print("INPROGRESS: " + str(inprogress))
print("COMPLETED : " + str(completed))
print("CANCELLED : " + str(cancelled))
print("FAILED : " + str(failed))
print("-" * 50)
,而是仅评估Auth.logout()
(未应用Auth.logout
运营商)。