簡體   English   中英

ReferenceError:結果未定義(Angularjs)

[英]ReferenceError: result is not defined (Angularjs)

我是新來的有角度的人,我對這個問題感到困惑,不知道為什么會這樣,任何想法都會有所幫助。

這是我定義的服務:

    window.app.factory 'fetchService', ['$http', '$q', '$location', ($http, $q, $location) ->
      {
      estimate: (newEstimate) ->
        def = $q.defer()

        $http.post('/v2/delivery_estimates', newEstimate).
        then (result) ->
        def.resolve result.data
        , (result) ->
        def.reject result.data
        def.promise
}]

在這里,window.app被映射到angular.module('appName',[...])

這是我的控制器:

    window.app.controller 'deliveryCtrl', [  'fetchService', (fetchService) ->

    $scope.setDefaults = ->
    {.... few code ....}
    fetchService.estimate(initialEstimate)
                         .then (result) ->
                           $scope.dWindows = result.delivery_windows
                           $scope.uWindows = result.unavailable_windows
]

謝謝,

您的咖啡腳本似乎很奇怪。 這個:

then (result) ->
def.resolve result.data

應該:

then (result) ->
    def.resolve result.data

第二個功能也一樣

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM