Shree29
Shree29

Reputation: 644

How to use promises in the case below

I am new to angular and want to use ngtasty serverside pagination but I am getting some issue like this

I have initialize method which call getMetaData function which make API call and set the $scope.publishersModel = []; and other model on basis of api data

$scope.initialize = function () {
  $scope.publishersModel = [];
  $scope.sitesModel = [];
  $scope.getMetaData();
};

Also for getting data which is shown in table I have getData(selectedPublishers,selectedSites) function which takes the selected models as parameter and this function retrun the data like this

{ "header": [{"Date" :"Date"}, {"Site":"Site"}],
  "rows":[{"Publisher_Name":"FashionDivaDesign","Site":"FashionDivaDesign.com","Date":"2015-12-06",}],
  "pagination": {"size":668,"pages":"67","count":10}
}

but currently parameters i.e. getData(param) are not available which set after success of api call of getMetaData()

So any idea how I can manage this data dependency

Upvotes: 1

Views: 38

Answers (1)

malix
malix

Reputation: 3582

I think you need to encapsulate this in a service but you can try something like:

$scope.getMetaData().then(function(data){
    return getData(data.selectedPublishers,data.selectedSites)
})
.then(function(data){
    $scope.something = data.rows;  
});

If you provide a jsFiddle/Plunker/CodePen, the answer can be more precise...

Upvotes: 1

Related Questions