在角度js中成功返回一个pervious方法后,有没有办法调用一个方法? [英] Is there any way to call one method after a pervious method returned successfully in angular js?

查看:117
本文介绍了在角度js中成功返回一个pervious方法后,有没有办法调用一个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些函数来获取数据并将数据发布到服务器但是由于角度js的异步性质,下一个方法在前一个返回之前开始执行,返回空字符串,它在下一个函数中使用...我已读过很多关于诺言的文章和$ q和非他们为我工作............



i希望功能执行的方式他们写的是有什么办法吗?请帮助......



我的代码完全在我的本地系统上运行,但它没有在服务器(云)上运行预期的方式



请帮助...



我尝试过的事情:



i have some functions to fetch data and to post data to server but due to asynchronous nature of angular js the next method start executing before the previous one returns which returns empty string it is used in next functions...i have read a lot articles about promise and $q and non of them worked for me............

i want the fuctions execute in the way they are written is there is any way? pls help......

my code runs on my local system perfectly but it is not running the expected way on Server(cloud)

pls help...

What I have tried:

app.factory('myService', function ($http) {
    return {
        // 1st function
        serverCall: function (purchaseid) {
            return $http.get('/po/poidsearchid/' + purchaseid).then(function (response) {
                console.log(response.data);
                console.log("Hi in server call");
                return response.data;
            });
        },
        // 2nd function
        anotherFunctionCall: function (poid) {
            //console.log("Hi in another call");
            $http.post('/po/poid', poid);
               console.log("Hi in another call");
            

        },

        // 3rd function
        anotherFunctionCall1: function (poiditems) {
           
            $http.post('/po/poiditems', poiditems)
                console.log("Hi in another call 1111");
                 
            

        },

        anotherFunctionCall2: function (purchaseid) {
            
            return $http.get('/po/poiditemssearchid/' + purchaseid).then(function (response) {
                console.log(response.data);
                console.log("Hi in another call 222");
                return response.data;
               
            });

        }

推荐答案

q并且他们没有为我工作......... ...



i希望功能按照写入方式执行是否有任何方法?请帮助......



我的代码完全在我的本地系统上运行,但它没有在服务器(云)上运行预期的方式



请帮助...



我尝试过的事情:



q and non of them worked for me............

i want the fuctions execute in the way they are written is there is any way? pls help......

my code runs on my local system perfectly but it is not running the expected way on Server(cloud)

pls help...

What I have tried:

app.factory('myService', function (


http){
return {
// 第一个函数
serverCall: function (purchaseid){
return
http) { return { // 1st function serverCall: function (purchaseid) { return


http.get(< span class =code-string>' / po / poidsearchid /' + purchaseid).then(功能(响应){
console .log(re sponse.data);
console .log( 在服务器中你好称之为);
return response.data;
});
},
// 第二个函数
anotherFunctionCall: function (poid){
// console.log (你好,在另一个电话中);
http.get('/po/poidsearchid/' + purchaseid).then(function (response) { console.log(response.data); console.log("Hi in server call"); return response.data; }); }, // 2nd function anotherFunctionCall: function (poid) { //console.log("Hi in another call");


这篇关于在角度js中成功返回一个pervious方法后,有没有办法调用一个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆