AngularJs: Have method return synchronously when it calls $http or $resource internally

后端 未结 5 1848
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 05:48

Is there a way to wait on a promise so that you can get the actual result from it and return that instead of returning the promise itself? I\'m thinking of something simila

5条回答
  •  攒了一身酷
    2020-12-29 06:32

    My approach was create a function with OLD javascript objects as follows:

    var globalRequestSync = function (pUrl, pVerbo, pCallBack) {
    
            httpRequest = new XMLHttpRequest();
            httpRequest.onreadystatechange = function () {
    
                if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                    pCallBack(httpRequest.responseText);
                }
            }
            httpRequest.open(pVerbo, pUrl, false);
            httpRequest.send(null);
    
        };
    

提交回复
热议问题