【发布时间】:2016-07-10 20:33:04
【问题描述】:
我在咖啡脚本中有一个像这样的角度工厂:
angular.module('app').factory 'appFactory', ['$q', 'Api', 'Flash', ($q, Api, Flash) ->
obj = undefined
get = ->
if angular.isDefined(obj)
return $q.when(obj)
Api.AppInitializer.query().$promise.then ((response) ->
obj = response
return obj
)
{
get: get()
}
]
我从这样的控制器中调用它:
angular.module('app').controller 'appCtrl', ($scope, appFactory) ->
appFactory.get.then ((data) ->
$scope.obj = data
)
基本上我从工厂获取数据,如果数据当前未定义,我将发出 Api 请求来获取数据。这按预期工作。
现在我需要将令牌参数传递给工厂以获取特定记录:
angular.module('app').factory 'appFactory', ['$q', 'Api', 'Flash', ($q, Api, Flash) ->
obj = undefined
get = (token) ->
if angular.isDefined(obj)
return $q.when(obj)
Api.AppInitializer.get(token: token).$promise.then ((response) ->
obj = response
return obj
)
{
get: get()
}
]
我从这样的控制器中调用它:
angular.module('app').controller 'appCtrl', ($scope, appFactory) ->
token = $scope.current_user.token_id
appFactory.get(token).then ((data) ->
$scope.obj = data
)
现在我得到了错误
TypeError: appFactory.get 不是函数
如何将 token 参数传递给 appFactory.get?
【问题讨论】:
标签: javascript angularjs coffeescript