简体   繁体   English

ReferenceError:结果未定义(Angularjs)

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

I'm new to angular, and i'm stuck with this issue, not sure why is this happening any thoughts would be helpful. 我是新来的有角度的人,我对这个问题感到困惑,不知道为什么会这样,任何想法都会有所帮助。

This is my service defined : 这是我定义的服务:

    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
}]

Here window.app is mapped to angular.module('appName',[...]) 在这里,window.app被映射到angular.module('appName',[...])

This is my controller : 这是我的控制器:

    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
]

Thanks, 谢谢,

Your coffeescript seems odd. 您的咖啡脚本似乎很奇怪。 This: 这个:

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

should be: 应该:

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

Same thing for the second function 第二个功能也一样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM