service portal how to get data from server to client

sam1212
Mega Expert

Hi All,

This looks simple but i am unable to figure out

i am getting the data from server to client but i unable to access the variable outside the function

here i am getting the watchlist from server and keeping in $scope.ta1 but if i try to keep outside the function i am not able to access

spUtil.update($scope).then(function(data){

              $scope.ta1=data.watchlistValues[0].name;

alert($scope.ta1);//working good

});

alert($scope.ta1);//not working

Any help is appreciated.

11 REPLIES 11

sam1212
Mega Expert

Hi Guys,



I am not sure what is difference between these two functions



This is not working


spUtil.update($scope).then(function(data){



//here you we can not assign or return anything ..



return data.watchlistValues;


});






My issue got solved by using



c.server.get({



                      action: "value"



            }).then(function(response) {


return response.data.watchlistValues;


});




If possible can you explain the difference between the two cases.


server.update and spUtil.update will update the data in scope from the server script. The server.get method does not pass along the whole data object to the server, and also does not update the data on scope, instead it returns the server script output in the form of the "response" property in the callbackco



Not sure if that makes sense, but you could have used the "update" method if you would have done something like this:



data.watchlistValues = [];


if (input)


        data.watchlistValues = input.watchlistValues;