I have an angularjs app with the following factory method that does live API call:
//Return SP json by SPID
azureMobileClient.getSPjsonBySPID = function (callback, spid)
{
azureMobileClient.azureMSC.invokeApi("get_spjson_byspid", {
parameters: {
spid: spid
},
method: "get"
}).done(function (results) {
//console.log(results.result);
callback(results.result);
}, function (error) {
alert(error.message);
});
}
And I have the following controller's method that consume it
$scope.getSPName = function (spid)
{
console.log("SPID:", spid);
var returnedName;
AzureMobileClient.getSPjsonBySPID(function (item)
{
console.log("item.fullname:", item.fullname);
returnedName = item.fullname;
}, spid);
return returnedName;
}
And this is how I am currently attempting to bind the returned item.fullname in my view (inside ng-repeat):
<p>
{{getSPName(t.parsedjsondata.SPId)}}
</p>
The problem is that the binding does not work although I do see the value of the console.log() with the correct item.fullname. I am guessing that this has to do with the delay of the API call and I need to insert $scope.$apply() somewhere but I am not sure what to do.