0
我有以下的$資源工廠:
app.factory "FeatureKey", ($resource) ->
$resource "/api/v1/feature_keys/:id", { id: "@id" }
在指令中,我使用它像這樣:
@search = (term) ->
FeatureKey.query(name: term).$promise.then (keys) =>
if keys.length > 0
@keys = keys
else
@keys = [{id: 0, name: term}]
@current.key = @keys[0]
我想什麼是最邏輯的移動到$資源工廠讓我的指令方法看起來像這樣:
@search = (term) ->
FeatureKey.search(term).$promise.then (keys) =>
@keys = keys
@current.key = @keys[0]
好吧,只是改變了所需的重構。那樣呢? – Nathan