Synchronous Call AngularJS -
this question has answer here:
method 1
{ var myform = getform(); var myvar = $sce.trustashtml(myform); }
method 2
var getform = function () { var form = ""; //api call here using custom service .then( function (response) { form = //processing here }, function (response) { } return form; };
in below scenario calling getform()
method , need processed data form variable. return empty before processing.
how can make call sync can getform()
return processed data , returns method 1
deal promise here:
var myform = getform().then( (form) => { $sce.trustashtml($sce.valueof(form)) }, (error) => { // getform - fail });
method 2 - return promise instead form value
var getform = function () { return //api call here using custom service };
or easier:
yourservice.servicemethod().then( (form) => { $sce.trustashtml(form) }, (error) => { // getform - fail });
Comments
Post a Comment