无法同时使用两条路线

时间:2019-01-07 15:15:59

标签: node.js angularjs mean-stack

我正在尝试使用两条路线来更新mongod中的值。这是我正在做的事情:如果routeA成功,则继续进行routeB,但是我的问题是,当routeA成功时,它不会继续进行routeB,我需要再次单击,它将继续进行routeB

这是我的代码:

service.js

bloodrequestFactory.editBloodrequest = function(id) {
    return $http.put('/api/editbloodrequest', id);
};

bloodrequestFactory.editBloodstock = function(id) {
    return $http.put('/api/editbloodstock', id);
};

controller.js

 app.updateReceipt = function(newReceipt,newEmail, valid,valid) {
        app.errorMsg = false; 
        app.disabled = true; 

        if (valid) {
            var userObject = {}; 
            userObject._id = app.currentUser; 
            userObject.receipt_no = $scope.newReceipt; 
            userObject.person_claimed = $scope.newEmail; 

            Bloodrequest.editBloodrequest(userObject).then(function(data) {

                if (data.data.success) {
                    app.successMsg = data.data.message; 


                    $timeout(function() {
                        app.emailForm.receipt_no.$setPristine(); 
                        app.emailForm.receipt_no.$setUntouched(); 
                        app.emailForm.person_claimed.$setPristine(); 
                        app.emailForm.person_claimed.$setUntouched(); 
                        app.successMsg = false; 
                        app.disabled = false; 
                    }, 2000);
                    updateStock();

                } else {
                    app.errorMsg = data.data.message;
                    app.disabled = false; 
                }
            });
        } else {
            app.errorMsg = 'Please ensure form is filled out properly';
            app.disabled = false; 
        }
    };

function updateStock(){
    app.updateNum = function(newValue, newBloodneeded, newBloodgroup) {

        var userObject = {}; 
        userObject._id = app.currentUser; 
        userObject.no_of_bags = $scope.newValue; 
        userObject.blood_needed = $scope.newBloodneeded; 
        userObject.blood_group = $scope.newBloodgroup; 

        Bloodrequest.editBloodstock(userObject).then(function(data) {
            if (data.data.success) {
                app.successMsg = data.data.message;

            } else {
                app.errorMsg = data.data.message;
                app.disabled = false; 
            }
        });
};  

}

在我的终端中,这是当我单击html中的“提交”按钮时发生的情况:

第一次点击: PUT /api/editbloodrequest 200 4.237 ms - 36

第二次点击:

PUT /api/editbloodrequest 200 5.548 ms - 36
PUT /api/editbloodstock 200 4.738 ms - 36

0 个答案:

没有答案