Synchronous Call AngularJS -


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

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -