Angular和CoffeeScript - 承诺功能无响应/工作

时间:2016-05-31 00:23:36

标签: javascript angularjs coffeescript promise

我是CoffeeScript的新手,我正在尝试在函数中编写一个promise。我使用了这个参考 - Chaining Promises in Coffeescript。但是当我对其进行编码时,我收到错误我输入.then (response) - TypeError: getter.then is not a function,如果我输入.then(respone) - response is not defined,我会收到此错误。这是特定服务的代码。帮助将不胜感激。

angular.module("deloitte.closeCalendar").factory('labPreferencesService', [ '$location','baseApiService','$routeParams','$translate','labService',( $location, api, $routeParams, $translate, labService) ->
  service = {}
  selectClient = new Object();

  service.setClient = (client) ->
    localStorage.clear();
    delete selectClient[0]; 
    selectClient[0] = client;  
    localStorage.setItem('name', JSON.stringify(selectClient[0]));
    console.log("Name Set!")

  service.getClient = (scope) ->
    if (Object.keys(selectClient).length == 0)
      console.log("Select Client was empty!")
      getter = localStorage.getItem('name')
      getter.then (response) ->display = response;
      console.log (display);
    else
    console.log("Select Client had data !");
    console.log(selectClient);


  return service
])

0 个答案:

没有答案