2015-02-06 165 views
0

我是新来的角度,我坚持这个问题,不知道为什么会发生这种情况 任何想法都会有所帮助。ReferenceError:结果未定义(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 
] 

感谢,

回答

2

你的CoffeeScript似乎奇。这:

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

应该是:我是相当新的咖啡脚本藏汉:-)第二功能

+0

感谢

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

同样的事情 – rajesh023 2015-02-06 09:44:56