Angular js应用程序无法处理多个请求

时间:2018-01-05 07:18:44

标签: javascript angularjs wcf

我正在将wcf休息服务用于angular js应用程序。我正在尝试将多个请求发布到wcf服务。 Angular js应用程序调用wcf服务并接收第一个请求,但它无法接收第二个请求。我希望当第一个请求成功时,它应该继续第二次请求..

这是脚本代码。

 var app = angular.module("WebClientModule", [])

        .controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {

            $scope.OperType = 1;

            //1 Mean New Entry  

            //To Clear all input controls.  
            function ClearModels() {
                $scope.OperType = 1;
                $scope.Tittle = "";
                $scope.First_Name = "";
                $scope.Last_Name = "";
                $scope.Gender = "";
                $scope.DOB = "";
                $scope.Mobile = "";
                $scope.House_No = "";

                $scope.Streent_Name = "";
                $scope.Country = "";
                $scope.Post_Code = "";
                $scope.Occupation = "";

                $scope.Account_Number = "";
            }
            $scope.CeditCardApplication = function () {
                var ApplicationDeatils = {
                    Tittle: $scope.Tittle,
                    First_Name: $scope.First_Name,
                    Last_Name: $scope.Last_Name,
                    Gender: $scope.Gender,
                    DOB: $scope.DOB,
                    Mobile: $scope.Mobile,
                    House_No: $scope.House_No,
                    Streent_Name: $scope.Streent_Name,
                    Country: $scope.Country,
                    Post_Code: $scope.Post_Code,
                    Occupation: $scope.Occupation,
                    Account_Number: $scope.Account_Number 
                };
                myService.ApplicationDeatilsCheck(ApplicationDeatils).then(function (pl) {
                    console.log(pl.data)
                    if (pl.data) {
                        $scope.msg = "User information is correct  !"**//Hits until here but does not go furture**

                        myService.ApplicationCreditScoreCheck(ApplicationDeatils1).then(function (p2) {
                            console.log(p2.data)

                            if (p2.data) {

                                $scope.msg = "We can offer you £6000";

                            } else {
                                $scope.msg = "Application failed !";
                                console.log("Some error Occured" + err);
                            }
                        }, function (err) {
                            $scope.msg = "Application failed!";
                            console.log("Some error Occured" + err);
                        });
                    };

                }); // <-- missing )
            } // <-- missing }
        }]);



    app.service("myService", function ($http) {

        this.ApplicationDeatilsCheck = function (ApplicationDeatils) {
            return $http.post("http://localhost:52098/HalifaxIISService.svc/CreateCurrentAccountCheck", JSON.stringify(ApplicationDeatils));
        }
        this.ApplicationCreditScoreCheck = function (ApplicationDeatils) {
            return $http.post("http://localhost:52098/HalifaxIISService.svc/cheekCreditScore", JSON.stringify(ApplicationDeatils));
        }

    });

Angular code ..直到那之后才开始工作..

**myService.ApplicationDeatilsCheck(ApplicationDeatils).then(function (pl) {
                    console.log(pl.data)
                    if (pl.data) {
                        $scope.msg = "User information is correct  !"**//Hits until here but does not go furture****

1 个答案:

答案 0 :(得分:1)

试试这个

var app = angular.module("WebClientModule", [])
.controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {

                $scope.OperType = 1;

                //1 Mean New Entry  

                //To Clear all input controls.  
                function ClearModels() {
                    $scope.OperType = 1;
                    $scope.Tittle = "";
                    $scope.First_Name = "";
                    $scope.Last_Name = "";
                    $scope.Gender = "";
                    $scope.DOB = "";
                    $scope.Mobile = "";
                    $scope.House_No = "";

                    $scope.Streent_Name = "";
                    $scope.Country = "";
                    $scope.Post_Code = "";
                    $scope.Occupation = "";

                    $scope.Account_Number = "";
                }
                $scope.CeditCardApplication = function () {
                    var ApplicationDeatils = {
                        Tittle: $scope.Tittle,
                        First_Name: $scope.First_Name,
                        Last_Name: $scope.Last_Name,
                        Gender: $scope.Gender,
                        DOB: $scope.DOB,
                        Mobile: $scope.Mobile,
                        House_No: $scope.House_No,
                        Streent_Name: $scope.Streent_Name,
                        Country: $scope.Country,
                        Post_Code: $scope.Post_Code,
                        Occupation: $scope.Occupation,
                        Account_Number: $scope.Account_Number 
                    };
                    myService.ApplicationDeatilsCheck(ApplicationDeatils).then(function (pl) {
                        console.log(pl.data)
                        if (pl.data) {
                            $scope.msg = "User information is correct  !"**//Hits until here but does not go furture**


                        };//Error on this line . Expression Expected 

                    }); // <-- missing )


                     myService.ApplicationCreditScoreCheck(ApplicationDeatils1).then(function (p2) {
                        console.log(p2.data)

                        if (p2.data) {

                            $scope.msg = "We can offer you £6000";

                        } else {
                            $scope.msg = "Application failed !";
                            console.log("Some error Occured" + err);
                        }
                    }, function (err) {
                        $scope.msg = "Application failed!";
                        console.log("Some error Occured" + err);
                    });


                } // <-- missing }
            }]);



        app.service("myService", function ($http) {

            this.ApplicationDeatilsCheck = function (ApplicationDeatils) {
                return $http.post("http://localhost:52098/HalifaxIISService.svc/CreateCurrentAccountCheck", JSON.stringify(ApplicationDeatils));
            }
            this.ApplicationCreditScoreCheck = function (ApplicationDeatils) {
                return $http.post("http://localhost:52098/HalifaxIISService.svc/cheekCreditScore", JSON.stringify(ApplicationDeatils));
            }

        });