angularjs服务工厂函数不是函数

aamkag61  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(198)

我正在调用一个服务函数,并在处理的结果中调用另一个服务函数。第一个(outter)工作,处理结果,并根据结果调用第二个服务函数。但是,第二个服务函数返回一个错误 clientService.getClient(...).then is not a function . 相同的服务工厂,功能设置和调用相同。

.factory("clientService", function($http,$q) {

  function getDataSet(typeID) {
    // retrieve full data client list from server
  }

  function getClient(id,typeID) {
    // return client data from already retrieved full client list
  }

  return  {
    getDataSet: function(typeID) {
      return getDataSet(typeID) ;
    },
    getClient: function(id,typeID) {
      return getClient(id,typeID) ;
    }
  }
})

…我在我的控制器里打电话

clientService.getDataSet(2)   // <-- works fine
.then(function(response) {
  if (response.list != null) {
    $scope.clientsList = response.list ;  // <-- list retrieved successfully
    if ($stateParams.openID) {
      clientService.getClient($stateParams.openID,2)  // <-- Error: "clientService.getClient(...).then is not a function"
      .then(function(clientResponse) {
        // process client data
       }) ;
    }
  } else {
    logResponse("Client list was is empty") ;
  }
}) ;

我被这个弄糊涂了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题