Link to home
Start Free TrialLog in
Avatar of Isaac Johnson
Isaac JohnsonFlag for United States of America

asked on

How to pass control on radio button selected/clicked prior to submit button click

I have completed the first display for SPA.
I want to pass control to a function handleAnswerRadioClick when one of
the radio buttons is selected.  Then on submit attempt to Vote Now.

Basically, if successful display addvote.html otherwise alreadyvoted.html

// index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=08636&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=tmruk%40amerihealthcaritas%2Ecom&lob=1&fname=Timothy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Mruk&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Timothy+Mruk&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = getCookie("ismanager");
            $scope.UserId = getCookie("emplid"); //
            $scope.FirstName = getCookie("fname");
            $scope.LastName = getCookie("lname");
            $scope.EmailAddress = getCookie("email");
            $scope.UserName = getCookie("username");
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }
       

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
           

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else
                    $scope.error = false;
            };
           
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,
                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            //SetUser($scope);  ?? Production
//==== Added 05/21/2019                      
            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ijohnson/0").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
           
            $scope.handleAnswerRadioClick = function (data) {
                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };
   //==== end new code 05/21/2019        
        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {
            
            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();
                 
                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);
                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            return service;
        }]);
       

        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {
            $routeProvider
            .when("/", {
                 
                templateUrl: "/api-test-pages/Quick-Survey/survey.html",
                
                controller: "VoteCtrl",
                // it's is good to download the data before displaying the template without the data
                // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                resolve: {
                    qa: ["VoteService", "$route", function (VoteService, $route) {
                        return VoteService.pageInit();
                    }]
                }

            }).
            otherwise({
                redirectTo: '/'
            });
        }]);

       

       

      

       
     </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

// =====survey.html

<div>
    <h2>{{QuestionText}}</h2>
    <div ng-hide="!!Answer">please select an answer</div>
    <br ng-repeat-start="a in Answers track by a.Id" />
    <input id="button{{a.AnswerText}}" name="selection" value="{{a.AnswerText}}" type="radio" ng-model="$parent.Answer" />
    <label for="button{{a.AnswerText}}" ng-repeat-end>{{a.AnswerText}}</label>
    <br />
    <span ng-show="error&&!Answer">error no answer selected</span>


    <br />
    <br />
    <input id="surveybtn" type="submit" value="Vote Now" ng-click="AddVote()" />

</div>

Open in new window

onButtonClicked.png
Thanks.png
alreadyvoted.png
Avatar of leakim971
leakim971
Flag of Guadeloupe image

you should put all your Ajax call in the service section.
Please note we use $q to have asynchronous call and use promise so your application is smooth and it's a pleasure to use it.

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};

            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();
                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);
                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ijohnson/0").success(function (data, status, headers, config) {
                    deferred.resolve(data);
                }).error(function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);

Open in new window


regarding your question, you've two way to achieve your goal which is not really following your logic.
1st one : when the user click on the vote button, we call addVote which check if something is selected (current code) and after check the number of vote with the service VoteService.getUserVoteCount(). It return true or false (I'm not sure because I don't see yoru data, should I trust you like a blind?). According it's false or true we redirect to the right page


Here the new addVote function, replace the previous one :
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if(VoteService.getUserVoteCount().then(function(isAlreadyVoted) {
                        if( isAlreadyVoted )
                            $location.redirect("/alreadyvoted");
                        else
                            $location.redirect("/addvote");
                    });
                }
            };

Open in new window


I'm pretty that will not work, so please send me back the index.html only and the chrome debug part.
The data sent by the following call would be great too :
"/API/quick-survey/api/Vote/GetUserVoteCount/866/ijohnson/0"
Avatar of Isaac Johnson

ASKER

I lost my first display.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=08636&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=tmruk%40amerihealthcaritas%2Ecom&lob=1&fname=Timothy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Mruk&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Timothy+Mruk&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = getCookie("ismanager");
            $scope.UserId = getCookie("emplid"); //
            $scope.FirstName = getCookie("fname");
            $scope.LastName = getCookie("lname");
            $scope.EmailAddress = getCookie("email");
            $scope.UserName = getCookie("username");
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }
       

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
           

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if(VoteService.getUserVoteCount().then(function(isAlreadyVoted) {
                        if( isAlreadyVoted )
                            $location.redirect("/alreadyvoted");
                    else
                            $location.redirect("/addvote");
                    })
                );
           
                    $scope.voteRequest = {
                        VoteId: null,
                        VoteDate: null,
                        UserName: $scope.UserName,
                        VoterFname: $scope.FirstName,
                        VoterLname: $scope.LastName,
                        Id: null,
                        QuestionId: null,
                 
                        QuestionText: "",
                        AnswerText: ""
                    };
                    SetCookiesForDebugging();
                    //SetUser($scope);  ?? Production
                      
            

                    //radio button click on request form
                    // 05/21/2019 put this in request by zone ????   
                    $scope.handleAnswerRadioClick = function (data) {
                  
                        $scope.voteRequest.QuestionId = data.QuestionId;
                        $scope.voteRequest.Id = data.Id;
                        $scope.voteRequest.AnswerText = data.AnswerText;
                    };
             
                };

                // service(s)
                app.factory("VoteService", ["$http", "$q", function ($http, $q) {

                    var service = {};

                    //Gets all data for page.
                    var questionNumber = 0;
                    service.pageInit = function () {
                        var deferred = $q.defer();
                        $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                            deferred.resolve(response.data);
                        }, function (error) {
                            console.error(error);
                            deferred.reject("error");
                        });
                        return deferred.promise;
                    };

                    // inserts new request
                    service.insertRequest = function () {
                        var deferred = $q.defer();
                        $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                            deferred.resolve(data); // you should send back something usefull like : {"success":true}
                            console.log("success");
                        }, function (data, status, headers, config) {
                            console.log("error!");
                            console.log(data);
                            deferred.reject("error");
                        });
                        return deferred.promise;
                    };

                    // checks if user already voted for a question
                    // get true or false
                    service.getUserVoteCount = function () {
                        var deferred = $q.defer();
                        $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ijohnson/0").success(function (data, status, headers, config) {
                            deferred.resolve(data);
                        }).error(function (data, status, headers, config) {
                            console.log(status);
                            deferred.reject("error");
                        });
                        return deferred.promise;
                    };

                    return service;
                }]);
       

                // route(s)
                app.config(["$routeProvider", function ($routeProvider) {
                    $routeProvider
                    .when("/", {
                 
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",
                
                        controller: "VoteCtrl",
                        // it's is good to download the data before displaying the template without the data
                        // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                        resolve: {
                            qa: ["VoteService", "$route", function (VoteService, $route) {
                                return VoteService.pageInit();
                            }]
                        }

                    }).
                    otherwise({
                        redirectTo: '/'
                    });
                }]);
            
            }
        }])
     </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

0522Error.png
0522ReurnVote.png
you put the whole code, including the services AND the routes in the VoteCtrl controller block
I still do not see the first display.

Do I also need to expand the routes code.
You never showed any routes or am I mistaken.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName; 
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }
       

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {

            SetCookiesForDebugging();
            SetUser($scope);

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;

            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.redirect("/alreadyvoted");
                    else
                            $location.redirect("/addvote");
                    }));

                    $scope.voteRequest = {
                        VoteId: null,
                        VoteDate: null,
                        UserName: $scope.UserName,
                        VoterFname: $scope.FirstName,
                        VoterLname: $scope.LastName,
                        Id: null,
                        QuestionId: null,

                        QuestionText: "",
                        AnswerText: ""
                    };
                    // SetCookiesForDebugging();
                    // SetUser($scope);  

                    // inserts new request
                    $scope.insertRequest = function () {

                        $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                            alert("success");
                        }, function (data, status, headers, config) {
                            console.log("error!");
                            console.log(data);
                        });
                    };

                    // checks if user already voted for a question
                    $scope.getUserVoteCount = function () {

                        // get true or false
                        $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                            $scope.activeQuestions = data;
                        }).error(function (data, status, headers, config) {
                            console.log(status);
                        });
                    };

                    //radio button click on request form
                    // 05/21/2019 put this in request by zone ????   
                    $scope.handleAnswerRadioClick = function (data) {

                        $scope.voteRequest.QuestionId = data.QuestionId;
                        $scope.voteRequest.Id = data.Id;
                        $scope.voteRequest.AnswerText = data.AnswerText;
                    };

                    // service(s)
                    app.factory("VoteService", ["$http", "$q", function ($http, $q) {

                        var service = {};

                        //Gets all data for page.
                        var questionNumber = 0;
                        service.pageInit = function () {
                            var deferred = $q.defer();
                            $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                                deferred.resolve(response.data);
                            }, function (error) {
                                console.error(error);
                                deferred.reject("error");
                            });
                            return deferred.promise;
                        };

                        // inserts new request
                        service.insertRequest = function () {
                            var deferred = $q.defer();
                            $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                                deferred.resolve(data); // you should send back something usefull like : {"success":true}
                                console.log("success");
                            }, function (data, status, headers, config) {
                                console.log("error!");
                                console.log(data);
                                deferred.reject("error");
                            });
                            return deferred.promise;
                        };

                        // checks if user already voted for a question
                        // get true or false
                        service.getUserVoteCount = function () {
                            var deferred = $q.defer();
                            $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                                deferred.resolve(data);
                            }).error(function (data, status, headers, config) {
                                console.log(status);
                                deferred.reject("error");
                            });
                            return deferred.promise;
                        };

                        return service;

                    }]);

                    // route(s)
                    app.config(["$routeProvider", function ($routeProvider) {
                        $routeProvider
                        .when("/", {

                            templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                            controller: "VoteCtrl",
                            // it's is good to download the data before displaying the template without the data
                            // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                            resolve: {
                                qa: ["VoteService", "$route", function (VoteService, $route) {
                                    return VoteService.pageInit();
                                }]
                            }

                        }).
                        otherwise({
                            redirectTo: '/'
                        });
                    }]);
                };
            };
        }]);
             
     </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

what block en at line 199 ?
and what block end at line 196 ?

not sure why you go so far from the previous working code (from your previous post)
The code has not worked since I moved everything to service or even before with new logic.
if I click on minus sign at voteCtrl all code is hidden up to but not including <body> tag.
The old version closes up to but not including voteservice and routeprivider.
I have both in the code block.
I cleaned up to syntax errors on block end.
== latest version== with latest solution ==
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName; 
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }
       

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {

            SetCookiesForDebugging();
            SetUser($scope);

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;

            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.redirect("/alreadyvoted");
                    else 
                            $location.redirect("/addvote");
                    });
                }
            };

            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            // SetCookiesForDebugging();
            // SetUser($scope);  

            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????   
            $scope.handleAnswerRadioClick = function (data) {

                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };

            // service(s)
            app.factory("VoteService", ["$http", "$q", function ($http, $q) {

                var service = {};

                //Gets all data for page.
                var questionNumber = 0;
                service.pageInit = function () {
                    var deferred = $q.defer();
                    $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                        deferred.resolve(response.data);
                    }, function (error) {
                        console.error(error);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };

                // inserts new request
                service.insertRequest = function () {
                    var deferred = $q.defer();
                    $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                        deferred.resolve(data); // you should send back something usefull like : {"success":true}
                        console.log("success");
                    }, function (data, status, headers, config) {
                        console.log("error!");
                        console.log(data);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };

                // checks if user already voted for a question
                // get true or false
                service.getUserVoteCount = function () {
                    var deferred = $q.defer();
                    $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                        deferred.resolve(data);
                    }).error(function (data, status, headers, config) {
                        console.log(status);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };

                return service;

            }]);

            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {
                $routeProvider
                .when("/", {

                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            return VoteService.pageInit();
                        }]
                    }

                }).
                otherwise({
                    redirectTo: '/'
                });

            }]);
        }]);
         </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

===== old version before changes show first display=====

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName; 
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }
       

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
           

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else
                    $scope.error = false;
            };
           
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,
                 
                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);  
                      
            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
           // 05/21/2019 put this in request by zone ????   
            $scope.handleAnswerRadioClick = function (data) {
                  
                  $scope.voteRequest.QuestionId = data.QuestionId;
                  $scope.voteRequest.Id = data.Id;
                  $scope.voteRequest.AnswerText = data.AnswerText;
              };
             
          }]);

            // service(s)
            app.factory("VoteService", ["$http", "$q", function ($http, $q) {
            
                var service = {};
                //Gets all data for page.
                var questionNumber = 0;
                service.pageInit = function () {
                    var deferred = $q.defer();
                 
                    $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                        deferred.resolve(response.data);
                        
                    }, function (error) {
                        console.error(error);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };
                return service;
            }]);
       

            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {
                $routeProvider
                .when("/", {
                 
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",
                
                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            return VoteService.pageInit();
                        }]
                    }

                }).
                otherwise({
                    redirectTo: '/'
                });
            }]);
            
              
     </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

New Code stops.  The Network shows attached.
newCodeStop.png
I just want to clarify that I inherited this app with very little experience with angularjs.

I did manage to get back the primary display and working on transfer to other displays.

The enclosed code gets me the primary display..  I have not been able to reach the secondary
display.  I am looking at the stored procedure trying to factor in isAlreadyVoted . Not sure
if the AddVote function change I made is correct.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {


            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.redirect("~/alreadyvoted.html");
                    else
                            $location.redirect("~/addvote.html");
                    }));
                }
            };
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                    //$scope.isAlreadyVoted = data.success;  // added 5/23/2019
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {

                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            return service;
            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                    deferred.resolve(data);
                }).error(function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {
            $routeProvider
            .when("/", {

                templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                controller: "VoteCtrl",
                // it's is good to download the data before displaying the template without the data
                // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                resolve: {
                    qa: ["VoteService", "$route", function (VoteService, $route) {
                        return VoteService.pageInit();
                    }]
                }

            }).
                              
            otherwise({
                redirectTo: '/'
            });
        }]);


    </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

thank you for the updates.
could you share some data response from the following API call :
/API/quick-survey/api/Vote/GetUserVoteCount/866/ijohnson/0
What this API call is supposed to return, I need to see the JSON(?) response
let's focus on GetUserVoteCount before AddVote
what is this line 146 for ? a return mid of a function with no test.
why did you add this line?
The data returned is the count

The correct API call should be:
/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405
the question id and username which will be values in the cookie
which returns 0 or 1 as count 0 being no votes 1 being already voted
Is the count within data thats returned. Not sure where this value is relative to
angular or how I capture the value.

Line 146 in a mistake,  I thought I copied it from the code you sent me. Line 175 I think is okay

USE [dev_web_insight]
GO
/****** Object:  StoredProcedure [dbo].[q_quicksurvey_checkStatInteg]    Script Date: 5/23/2019 11:09:27 AM ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[q_quicksurvey_checkStatInteg]
(
@question_id as int,
@nt_username as varchar(80)
)
AS
SELECT     count(*) 
FROM         dbo.q_quicksurvey_votes
Where question_id = @question_id and nt_username = @nt_username

Open in new window

JSONcount.png
could you share the chrome debug please?
Debug attached.
0524Error.png
I will back on this problem late next week.

Please keep me inform this is getting critical

Isaac
Oh, no console errors, just sits where indicated in the chrome network display.
ok, so choose an answer and vote, and post the chrome debug after you clicked on vote.
Ok.  I'm back will do.
After vote clicked.

See attached. Does not present next page requested.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {


            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var AlreadyVoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.redirect("/alreadyvoted");
                    else
                            $location.redirect("/addvote");
                    }));
                }
            };
            
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                    
                    
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {

                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
             // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                    deferred.resolve(data);
                    AlreadyVoted = data.isAlreadyVoted;
                }).error(function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {
            $routeProvider
            .when("/", {

                templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                controller: "VoteCtrl",
                // it's is good to download the data before displaying the template without the data
                // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                resolve: {
                    qa: ["VoteService", "$route", function (VoteService, $route) {
                        return VoteService.insertRequest();
                    }]
                }

            }).
                              
            otherwise({
                redirectTo: '/'
            });
            $routeProvider
           .when("/", {

               templateUrl: "/api-test-pages/Quick-Survey/survey.html",

               controller: "VoteCtrl",
               // it's is good to download the data before displaying the template without the data
               // so all we found in resolve is gonna be "resolved" before display the page and running the controller
               resolve: {
                   qa: ["VoteService", "$route", function (VoteService, $route) {
                       return VoteService.pageInit();
                   }]
               }

           }).
                 

           otherwise({
               redirectTo: '/'
           });
        }]);


    </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

aftervoteclick.png
where is the iis 8 404 page coming from?
Its a missing favicon which I don't think will effect execution.

I fixed and made a location change in the code that should transfer pages.

I found some code a hadn't deleted as well.

Same results, no page transfer.

This scenario show add vote

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {


            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var AlreadyVoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                           $location.url = ("/alreadyvoted.html");
                    else
                            $location.url = ("/addvote.html");
                    }));
                }
            };
            
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                    
                    
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {   
                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
             // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                    deferred.resolve(data);
                    AlreadyVoted = data.isAlreadyVoted;
                }).error(function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {
           
            $routeProvider
           .when("/", {

               templateUrl: "/api-test-pages/Quick-Survey/survey.html",

               controller: "VoteCtrl",
               // it's is good to download the data before displaying the template without the data
               // so all we found in resolve is gonna be "resolved" before display the page and running the controller
               resolve: {
                   qa: ["VoteService", "$route", function (VoteService, $route) {
                       return VoteService.pageInit();
                   }]
               }

           }).
                 
                 

           otherwise({
               redirectTo: '/'
           });
        }]);


    </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

aftervoteclick1.png
aftervoteclick2.png
replace lines 65 to 78 by :
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.path("/alreadyvoted");
                        else
                            $location.path("/addvote");
                    }));
                }
            };

Open in new window


replace line 163 to 173 by  :
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function(data) {
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

Open in new window


replace line 181 to 182 by :
            $routeProvider
                .when("/alreadyvoted", {
                    templateUrl: "api-test-pages/Quick-Survey/alreadyvoted.html",
                })
                .when("/addvote", {
                    templateUrl: "api-test-pages/Quick-Survey/addvote.html",
                })
                .when("/", {

Open in new window



in
survey.html

Open in new window

replace : {{a.AnswerText}}
by : {{a.Id}}
Undefined error.  The possible answers are now numbers, should be text as before

// survey.html
<div>
    <h2>{{QuestionText}}</h2>
    <div ng-hide="!!Answer">please select an answer</div>
    <br ng-repeat-start="a in Answers track by a.Id" />
    <input id="button{{a.Id}}" name="selection" value="{{a.Id}}" type="radio" ng-model="$parent.Answer"  />
    <label for="button{{a.Id}}" ng-repeat-end>{{a.Id}}</label>
    <br />
    <span ng-show="error&&!Answer">error no answer selected</span>


    <br />
    <br />
    <input id="surveybtn" type="submit" value="Vote Now" ng-click="AddVote()" />

</div>
// code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>-->
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName; 
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }
       

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {

            SetCookiesForDebugging();
            //SetUser($scope);

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;

            $scope.error = false;

            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.AnswerText == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.redirect("/alreadyvoted");
                    else 
                            $location.redirect("/addvote");
                    }));
                }
            };

            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            // SetCookiesForDebugging();
            // SetUser($scope);  

            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405/0").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????   
            $scope.handleAnswerRadioClick = function (data) {

                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };

            // service(s)
            app.factory("VoteService", ["$http", "$q", function ($http, $q) {

                var service = {};

                //Gets all data for page.
                var questionNumber = 0;
                service.pageInit = function () {
                    var deferred = $q.defer();
                    $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                        deferred.resolve(response.data);
                    }, function (error) {
                        console.error(error);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };

                // inserts new request
                service.insertRequest = function () {
                    var deferred = $q.defer();
                    $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                        deferred.resolve(data); // you should send back something usefull like : {"success":true}
                        console.log("success");
                    }, function (data, status, headers, config) {
                        console.log("error!");
                        console.log(data);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };

                // checks if user already voted for a question
                // get true or false
                service.getUserVoteCount = function () {
                    var deferred = $q.defer();
                    $http.get("API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                        deferred.resolve(data);
                    }, function (data, status, headers, config) {
                        console.log(status);
                        deferred.reject("error");
                    });
                    return deferred.promise;
                };

                return service;

            }]);

            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {
                $routeProvider
                .when("/alreadyvoted", {
                    templateUrl: "api-test-pages/Quick-Survey/alreadyvoted.html",
                })
             
                .when("/addvote", {
                    templateUrl: "api-test-pages/Quick-Survey/addvote.html",
                })
            
                .when("/", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            return VoteService.pageInit();
                        }]
                    }

                }).
                  

           otherwise({
               redirectTo: '/'
           });
            }]);
        }])
         </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

ReferenceError.png
line 71 should be :
app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {

Open in new window


please post your survey.html
survey.html

<h2>{{QuestionText}}</h2>
    <div ng-hide="!!Answer">please select an answer</div>
    <br ng-repeat-start="a in Answers track by a.Id" />
    <input id="button{{a.Id}}" name="selection" value="{{a.Id}}" type="radio" ng-model="$parent.Answer"  />
    <label for="button{{a.Id}}" ng-repeat-end>{{a.Id}}</label>
    <br />
    <span ng-show="error&&!Answer">error no answer selected</span>


    <br />
    <br />
    <input id="surveybtn" type="submit" value="Vote Now" ng-click="AddVote()" />

</div>

Open in new window

Flipping to addvote.html but vote not added to table.

I have enclosed html for addvote, alreadyvoted plus code.

Can I change survey.html to  a.AnswerText

I added VoteService.AddVote() prior to $location.path("/addvote'")
but vote still not added to table.

The data is not populated in the html I'll have to see why.
It look like I can remove lines 140 thru 162 since they are now part of the services is that true?

//addvote.html no data populated but html appears but no vote added to table total votes is my number as lieral for now
<div>

    <p><b>Thanks for your Vote!</b></p>
    <p>Survey Results</p>
    <p>Question</p>
    <p>{{QuestionText}}</p>
    <br />
    <p>Results</p>
    
    <p>{{QuestionText}}</p> questions (100.00%)
    <br />
    Result for Answer: {{QuestionText}} questions is 100.0%
    <br />
    {{QuestionText}} (0.00%)
    <br />
    Result for Answer: {{[QuestionText}} is 0.0%
    <br />
    Total Votes: 2
    </div>
///  alreadyvoted.html
<div>

    <p><b>Thanks for your Vote!</b></p>
    <p><b>You already voted on this question. This survey only allows one vote per user. </b></p>
    <p>Survey Results</p>
    <p>Question</p>
    <p>{{QuestionText}}</p>
    <br />
    <p>Results</p>

    <p>{{QuestionText}}</p> questions (100.00%)
    <br />
    Result for Answer: {{QuestionText}} questions is 100.0%
    <br />
    {{QuestionText}}(0.00%)
    <br />
    Result for Answer: {{QuestionText}} is 0.0%
    <br />
    Total Votes: 2
</div>
// current code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var  AlreadyVoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.path("/alreadyvoted");
                    else
                        // execute VoteService.insertRequest
                            VoteService.AddVote();
                            $location.path("/addvote");
                    }));
                }
            };
            
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
            $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                    
                    
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {   
                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
             // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {
           
            $routeProvider
                .when("/alreadyvoted", {
                    templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                })
             
                .when("/addvote", {
                    templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                })
            
                .when("/", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
               // it's is good to download the data before displaying the template without the data
               // so all we found in resolve is gonna be "resolved" before display the page and running the controller
               resolve: {
                   qa: ["VoteService", "$route", function (VoteService, $route) {
                       return VoteService.pageInit();
                   }]
               }

           }).
                 
                 

           otherwise({
               redirectTo: '/'
           });
        }]);


    </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

/// API's
{
        [HttpPost]
        public IHttpActionResult AddVote(Vote v)
        {
            try
            {

                v.AddVote(v.QuestionId, v.Id, v.UserName);

                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [Route("api/Vote/GetSurveyResults/{id}")]
        [HttpGet]
        public IHttpActionResult GetSurveyResults(int id)
        {
            try
            {
                Vote v = new Vote();
                return Ok(v.GetSurveyResults(id));
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [Route("api/Vote/GetUserVoteCount/{id}/{userName}")]
        [HttpGet]
        public IHttpActionResult GetUserVoteCount(int id, string userName)
        {
            try
            {
                Vote v = new Vote();
                return Ok(v.UserVoteCount(id, userName));
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }

Open in new window

The possible answers are now numbers, should be text as before

Replace :
<label for="button{{a.Id}}" ng-repeat-end>{{a.Id}}</label>

Open in new window

by :
<label for="button{{a.Id}}" ng-repeat-end>{{a.AnswerText}}</label>

Open in new window

QuestionText
so now, could you confirm you go (check the URL) to /alreadyvoted or /voted path after voting?
I go to http://home-dev.kmhp.com/api-test-pages/Quick-Survey/index.html#!/addvote

but table is not updated.  After I vote, I vote again and it takes me to
http://home-dev.kmhp.com/api-test-pages/Quick-Survey/index.html#!/addvote   again.

Should I have $scope.voteRequest and $scope.handleAnswerRadioClick inside the app.factory?

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    
    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var  AlreadyVoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.path("/alreadyvoted");
                    else
                        // execute VoteService.insertRequest
                            VoteService.insertRequest();
                            $location.path("/addvote");
                    }));
                }
            };
            
            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
          /*  $scope.insertRequest = function () {

                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    alert("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                });
            };

            // checks if user already voted for a question
            $scope.getUserVoteCount = function () {

                // get true or false
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                    $scope.activeQuestions = data;
                    
                    
                }).error(function (data, status, headers, config) {
                    console.log(status);
                });
            };*/

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {   
                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;

                $scope.voteRequest.QuestionText = data.QuestionText
            };

        }]); 

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
             // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {
           
            $routeProvider
                .when("/alreadyvoted", {
                    templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                })
             
                .when("/addvote", {
                    templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                })
            
                .when("/", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
               // it's is good to download the data before displaying the template without the data
               // so all we found in resolve is gonna be "resolved" before display the page and running the controller
               resolve: {
                   qa: ["VoteService", "$route", function (VoteService, $route) {
                       return VoteService.pageInit();
                   }]
               }

           }).
                 
                 

           otherwise({
               redirectTo: '/'
           });
        }]);


    </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

the initial page was :
http://home-dev.kmhp.com/api-test-pages/Quick-Survey/index.html#!/
right?

if yes, could you open this page, vote and confirm you see now of of this path :
http://home-dev.kmhp.com/api-test-pages/Quick-Survey/index.html#!/alreadyvoted
or
http://home-dev.kmhp.com/api-test-pages/Quick-Survey/index.html#!/voted

if you move too fast I can get where you do something wrong.
good. now focus on this :

            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.path("/alreadyvoted");
                    else
                        // execute VoteService.insertRequest
                            VoteService.insertRequest();
                            $location.path("/addvote");
                    }));
                }
            };

Open in new window


the else part is bad, it should be :
                    else { // <--- note we open accolade because there's more than one line following, identition is very good (I use tab, one char big ident)
                        // execute VoteService.insertRequest
                            VoteService.insertRequest().then(function(status) {;
                                   if(status) // let's say status return true/1 or false/0 to know if the service successfuly saved
                                          $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                            });
                      } // <------ we close the accolade
                    }));
                }
            };

Open in new window

The response is alreadyvoted

http://home-dev.kmhp.com/api-test-pages/Quick-Survey/index.html#!/alreadyvoted

but this is the first vote and the table does not have the row for this vote.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {

            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var AlreadyVoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyVoted) {
                        if (isAlreadyVoted)
                            $location.path("/alreadyvoted");
                    else {
                        // execute VoteService.insertRequest
                        VoteService.insertRequest().then(function (status) {;
                        if (status) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    } // <------ we close the accolade
                    }));
                }
            };

            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
            /*  $scope.insertRequest = function () {

                  $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                      alert("success");
                  }, function (data, status, headers, config) {
                      console.log("error!");
                      console.log(data);
                  });
              };

              // checks if user already voted for a question
              $scope.getUserVoteCount = function () {

                  // get true or false
                  $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                      $scope.activeQuestions = data;


                  }).error(function (data, status, headers, config) {
                      console.log(status);
                  });
              };*/

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {
                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;

                $scope.voteRequest.QuestionText = data.QuestionText
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                //$http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                $http.post("/API/quick-survey/api/Vote/AddVote/866/4454/ij25405").then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {

                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {

            $routeProvider
                .when("/alreadyvoted", {
                    templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                })

                .when("/addvote", {
                    templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                })

                .when("/", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            return VoteService.pageInit();
                        }]
                    }

                }).



           otherwise({
               redirectTo: '/'
           });
        }]);


    </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

I fixed the constant already vote.   I now get a scope error when trying to present addvote
The scope error is attached.
At line 160:

$http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
$scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyvoted) {
                     
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                    else {
                        // execute VoteService.insertRequest
                        VoteService.insertRequest().then(function ($scope, status) {  // added scope
                        if (status = 0) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    }  
                    }));
                }
            };

====

service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                    isAlreadyvoted = data.isAlreadyvoted; // was getting undefined so this line added
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

Open in new window

scopeError.png
Check line 14 : $scope.Answer.Id
$scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyvoted) {
                     
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                    else {
                        // execute VoteService.insertRequest
alert($scope.Answer);
                        VoteService.insertRequest( $scope.Answer.Id ).then(function ($scope, status) {  // added scope
                        if (status = 0) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    }  
                    }));
                }
            };

Open in new window


Check line 2 : answerId
            // inserts new request
            service.insertRequest = function (answerId) {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", answerId).then(function (data, status, headers, config) {

Open in new window

Returns error answerId is not defined. answer

Addvote takes 3 parameters which are in $scope.voteRequest combined with $scope.handleAnswerRadioClick
I put in additional alerts everything is null or undefined except $scope.Answer
/// API Post
public class VoteController : ApiController
    {
        [HttpPost]
        public IHttpActionResult AddVote(Vote v)
        {
            try
            {

                v.AddVote(v.QuestionId, v.Id, v.UserName);

                return Ok();
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
/// index code
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
        function SetCookiesForDebugging() {
            var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
            document.cookie = thecookie;
        }

        // sets all scope variables based on associate cookie information.
        function SetUser($scope) {

            //Set User Information with Cookie data
            $scope.IsManager = document.cookie.ismanager;
            $scope.UserId = document.cookie.userName;
            $scope.FirstName = document.cookie.fname;
            $scope.LastName = document.cookie.lname;
            $scope.EmailAddress = document.cookie.email;
            $scope.UserName = document.username;
        }

        // loops through iNSIGHT cookie to retrieve specific value.
        // removes all HTML characters.
        function getCookie(name) {

            var cookiesArray = document.cookie.split("&");
            for (var i = 0; i < cookiesArray.length; i++) {

                var nameValueArray = cookiesArray[i].split("=");

                var cookieName = decodeURI(nameValueArray[0]);
                var cookieValue = nameValueArray[1].replace(/\+/g, '%20');
                cookieValue = decodeURIComponent(cookieValue);

                if (cookieName == name) {
                    return decodeURI(cookieValue);
                }

            }
        }


        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {
           
            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var isAlreadyvoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyvoted) {
                     
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                    else {
                        // execute VoteService.insertRequest
                        alert($scope.Answer)
                        alert($scope.userName)
                        alert($scope.voteRequest.Id)
                        alert($scope.voteRequest.QuestionId)
                        VoteService.insertRequest($scope.Answer.Id).then(function ($scope, status) {
                        if (status = 0) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    }  
                    }));
                }
            };

            $scope.voteRequest = {
                VoteId: null,
                VoteDate: null,
                UserName: $scope.UserName,
                VoterFname: $scope.FirstName,
                VoterLname: $scope.LastName,
                Id: null,
                QuestionId: null,

                QuestionText: "",
                AnswerText: ""
            };
            SetCookiesForDebugging();
            SetUser($scope);

            // inserts new request
            /*  $scope.insertRequest = function () {

                  $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function (data, status, headers, config) {
                      alert("success");
                  }, function (data, status, headers, config) {
                      console.log("error!");
                      console.log(data);
                  });
              };

              // checks if user already voted for a question
              $scope.getUserVoteCount = function () {

                  // get true or false
                  $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").success(function (data, status, headers, config) {
                      $scope.activeQuestions = data;


                  }).error(function (data, status, headers, config) {
                      console.log(status);
                  });
              };*/

            //radio button click on request form
            // 05/21/2019 put this in request by zone ????
            $scope.handleAnswerRadioClick = function (data) {
                $scope.voteRequest.QuestionId = data.QuestionId;
                $scope.voteRequest.Id = data.Id;
                $scope.voteRequest.AnswerText = data.AnswerText;

                //$scope.voteRequest.QuestionText = data.QuestionText
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
          
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);

                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", answerId).then(function (data, status, headers, config) {
                  
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                    isAlreadyvoted = data.isAlreadyvoted;
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {

                $routeProvider
                    .when("/alreadyvoted", {
                        templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                    })

                    .when("/addvote", {
                        templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                    })

                    .when("/", {
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                        controller: "VoteCtrl",
                        // it's is good to download the data before displaying the template without the data
                        // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                        resolve: {
                            qa: ["VoteService", "$route", function (VoteService, $route) {
                                return VoteService.pageInit();
                            }]
                        }

                    }).



               otherwise({
                   redirectTo: '/'
               });
            }]);
        </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

// inserts new request
            service.insertRequest = function (answerId) {
I put in additional alerts everything is null or undefined except $scope.Answer

nice, I believe you got something [Object]

so use :
alert(JSON.stringify($scope.Answer));

Open in new window

instead:
alert($scope.Answer);

Open in new window

How do I code survey.html so I can pickup the question_id from the query that is providing the
data for the html. I want the field hidden but accessible so I can build addvote key.  I already
have the AnswerId which you showed me.

<div>
    <h2>{{QuestionText}}</h2><br />
    <div ng-hide="!!Answer">please select an answer</div>
    <br ng-repeat-start="a in Answers track by a.Id" />
    <input id="button{{a.Id}}" name="selection" value="{{a.Id}}" type="radio" ng-model="$parent.Answer"  />
    <label for="button{{a.Id}}" ng-repeat-end>{{a.AnswerText}}</label>
    <br />
    <span ng-show="error&&!Answer">error no answer selected</span>


    <br />
    <br />
    <input id="surveybtn" type="submit" value="Vote Now" ng-click="AddVote()" />

</div>
//query

ALTER PROCEDURE [dbo].[q_quicksurvey_questions_get_current_surveys] 
(
@zone_id as int
)
AS
SELECT     TOP 100 PERCENT question_id, question_txt, question_end, question_stat_integ, question_show_results
FROM         dbo.q_quicksurvey_questions
WHERE     ((question_start <= GETDATE()) AND (question_end >= GETDATE())) AND (question_live = 1) AND (zone_id = @zone_id)
ORDER BY question_end

Open in new window

I made some changes but getting scope undefined when trying to enter api.
How do I inject scope into service.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
      

        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {
            function SetCookiesForDebugging() {
                var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
                document.cookie = thecookie;
            }
            // sets all scope variables based on associate cookie information.
            function SetUser($scope) {

                //Set User Information with Cookie data
                $scope.IsManager = document.cookie.ismanager;
                $scope.UserId = document.cookie.userName;
                $scope.FirstName = document.cookie.fname;
                $scope.LastName = document.cookie.lname;
                $scope.EmailAddress = document.cookie.email;
                $scope.UserName = document.cookie.username;
            }
            SetCookiesForDebugging();
            
            SetUser($scope);
            
            $scope.voteRequest =  {
                QuestionNum: 866,                    
                aId: 0,
                user: "ij25405",
                            
            }
            $scope.handleAnswerRadioClick = function (data) {
                $scope.voteRequest.QuestionId = data.QuestionId;
                //$scope.voteRequest.Id = data.Id;
                $scope.voteRequest.Id = Answer.Id
                $scope.voteRequest.AnswerText = data.AnswerText;
                
                //$scope.voteRequest.QuestionText = data.QuestionText
            };
            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var isAlreadyvoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyvoted) {
                     
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                    else {
                        // execute VoteService.insertRequest
                        aId = $scope.Answer;
                        alert(aId);
                        alert(JSON.stringify($scope.Answer));
                         
                        QuestionNum = 866;
                        alert(QuestionNum);
                         
                        alert($scope.voteRequest);
                        alert(JSON.stringify($scope.voteRequest));
                         
                        VoteService.insertRequest($scope.voteRequest).then(function ($scope, status) {
                        if (status = 0) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    }  
                    }));
                }
            };

         

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
             
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);
                    
                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function ($scope, data, status, headers, config) { // Error line of code
                  
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                }, function (data, status, headers, config) {
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                    isAlreadyvoted = data.isAlreadyvoted;
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {

                $routeProvider
                    .when("/alreadyvoted", {
                        templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                    })

                    .when("/addvote", {
                        templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                    })

                    .when("/", {
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                        controller: "VoteCtrl",
                        // it's is good to download the data before displaying the template without the data
                        // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                        resolve: {
                            qa: ["VoteService", "$route", function (VoteService, $route) {
                                return VoteService.pageInit();
                            }]
                        }

                    }).



               otherwise({
                   redirectTo: '/'
               });
            }]);
        </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

ScopeUndefined.png
How do I code survey.html so I can pickup the question_id from the query that is providing the
data for the html

survey.nomatterthextension is a template : DON'T put any code or JavaScript logic in

your issue is :
                    .when("/", {
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",

Open in new window


this should be something like :
                    .when("/question/:questionId", {
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",

Open in new window

so you can use line 104 (your latest code snippet) :
            service.pageInit = function (the_question_id) {

Open in new window

and line 107 :
                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/'+the_question_id)

Open in new window


if you want you can use both routes :
this one "/"
and this new one : "/:questionId

please note we use VoteService.pageInit(0)  for the route "/"
and we use VoteService.pageInit(questionNumberFromURL) for the route "/question/:questionId"

                .when("/", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            return VoteService.pageInit(0);
                        }]
                    }

                })

                .when("/question/:questionId", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            var questionNumberFromURL = $route.current.params.questionId;
                            return VoteService.pageInit(questionNumberFromURL);
                        }]
                    }

                }).

Open in new window


why  QuestionNum is 866,
but you call : $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0
instead : $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/866
?
what is "aId" ?
aId: 0,

is username (cookies) same as user($scope)

so we can do :
$scope.user = document.cookie.username
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-cookies.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <script type="text/javascript">

        // app
        var app = angular.module('quickSurveyApp', ["ngRoute", "ngCookies"]);

        // controller(s)
        app.controller("VoteCtrl", ["$scope", "qa", "$location",  "$routeParams", "VoteService", "UserService", function ($scope, qa, $location, $routeParams, VoteService, UserService) {

            UserService.SetCookiesForDebugging();
            angular.extend($scope, UserService.getUserContextFromCookies());
            angular.extend($scope, {
                QuestionNum: 866,
                aId: 0,
            });

            $scope.activeQuestions = $routeParams.questionId;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            $scope.error = false;

            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if(VoteService.getUserVoteCount($scope.UserName, $scope.QuestionNum).then(function (isAlreadyvoted) {
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                        else {
                            VoteService.insertRequest($scope.UserName, $scope.QuestionNum, $scope.Answer).then(function (saved) {
                                if (saved)
                                    $location.path("/addvote");
                            });
                        }
                    }));
                }
            };

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {
            var service = {};

            service.pageInit = function (question_id) {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Question/GetQuestionsByZone/"+question_id).then(function (response) {
                    deferred.resolve(response.data);
                }, function (response) {
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            // inserts new request
            service.insertRequest = function (username, question_id, answer_id) {
                var deferred = $q.defer();
                var voteRequestData = { userId: username, questionId: question_id, answerId: answer_id};
                $http.post("/API/quick-survey/api/Vote/AddVote", voteRequestData).then(function (response) { // Error line of code
                    deferred.resolve(!!response.data); // 0(not saved) or 1(saved) ?
                 }, function (response) {
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            // checks if user already voted for a question
            // return true or false
            service.getUserVoteCount = function (username, question_id) {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/" + question_id + "/" + username).then(function (response) {
                    deferred.resolve(response.data); // this return the number of vote : 0 or 1
                }, function (response) {
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);

        app.factory("UserService", ["$cookies", function($cookies) {
            var service = {};

            // Set cookies for debugging purpose
            service.SetCookiesForDebugging = function() {
                var some_context_data = {"departid":"351","jobtitle":"Digital+Developer","floor":"0","username":"ij25405","ps%5Fdeptname":"Digital+Experience","ps%5Fdeptid":"351","cost%5Fcenter":"351","birthday%5Fday":"16","birthday":"0","fsla":null,"nbsp":null,"psdeptname":"Digital+Experience","managerwholename":"Lawrence+Raffel","area":"215","mailstop":"%2D+None+Selected+%2D","managerid":"21286","departmentid":"0","extension":"2158635597","emplid":"ij25405","managerusername":"LR22638","deptname":"KY+Exec+Dir","cubeoffice%5Fno":"+","ismanager":"0","email":"ijohnson%40amerihealthcaritas%2Ecom","lob":"1","fname":"Isaacy","is%5Fuserlive":"1","psdeptid":"351","url":"%23","costcenter":"351","lname":"Johnson","company":"KEY","managerphone":"2159378142","is%5Fmanager":"0","wholename":"Isaac+Johnson","id":"13332","building":"0","guest":null};
                $cookies.put("context", JSON.stringify(some_context_data));
            }

            // get some context variables based on associate cookie information.
            service.getUserContextFromCookies = function() {
                //Get User Information from cookies data
                var context = JSON.parse($cookies.get("context"));
                return {
                    IsManager: context.ismanager,
                    UserId: context.userName,
                    FirstName: context.fname,
                    LastName: context.lname,
                    EmailAddress: context.email,
                    UserName: context.username,
                };
            }
            return service;

        }]);

        // route(s)
        app.config(["$routeProvider", function ($routeProvider) {

            $routeProvider
                .when("/alreadyvoted", {
                    templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                })
                .when("/addvote", {
                    templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                })
                .when("/", {
                    redirectTo: '/question/0'
                })
                .when("/question/:questionId", {
                    templateUrl: "/api-test-pages/Quick-Survey/survey.html",
                    controller: "VoteCtrl",
                    // it's is good to download the data before displaying the template without the data
                    // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                    resolve: {
                        qa: ["VoteService", "$route", function (VoteService, $route) {
                            var questionNumberFromURL = $route.current.params.questionId;
                            return VoteService.pageInit(questionNumberFromURL);
                        }]
                    }

                })
                .otherwise({
                    redirectTo: '/'
                });
        }]);
    </script>


</head>
<body ng-app="quickSurveyApp">
<div>
    <h1>Quick Survey</h1>
    <div ng-view></div>
</div>
</body>
</html>

Open in new window

QuestionNum is the id of the question
aId is the number of the answer
I hard coded the userId (ij25405) to insert test

My problem is a successful insert. The program does not like
anything I've tried when calling VoteService.insertRequest

Do I need to use $rootScope?  I've done some reading and I see using rootScope.
Should I be executing the insert outside the app.factory?
I also see that $scope is not meant to be used in app Service.

When trying to generate parameters for insert nothing seems available for the parameters at
this time so I hard coded for testing so I can test Insert.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
      

        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {
            function SetCookiesForDebugging() {
                var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
                document.cookie = thecookie;
            }
            // sets all scope variables based on associate cookie information.
            function SetUser($scope) {

                //Set User Information with Cookie data
                $scope.IsManager = document.cookie.ismanager;
                $scope.UserId = document.cookie.userName;
                $scope.FirstName = document.cookie.fname;
                $scope.LastName = document.cookie.lname;
                $scope.EmailAddress = document.cookie.email;
                $scope.UserName = document.cookie.username;
            }
            SetCookiesForDebugging();
            
            SetUser($scope);
            
            
            $scope.voteRequest =  {
                QuestionNum: 866,                    
                aId: 4454,
                userIn: "ij25405",
                            
            }
            $scope.handleAnswerRadioClick = function (data) {
                $scope.voteRequest.QuestionId = data.QuestionId;
                //$scope.voteRequest.Id = data.Id;
                $scope.voteRequest.Id = Answer.Id
                $scope.voteRequest.AnswerText = data.AnswerText;
                
                //$scope.voteRequest.QuestionText = data.QuestionText
            };
            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var isAlreadyvoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyvoted) {
                     
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                    else {
                        // execute VoteService.insertRequest
                        aId = $scope.Answer;
                        alert(aId);
                        //aId = JSON.stringify($scope.Answer)
                       //alert(JSON.stringify($scope.Answer));
                         
                        QuestionNum = 866;
                        alert(QuestionNum);
                        userIn = 'ij25405';
                        alert(userIn);
                        alert($scope.voteRequest);
                        alert(JSON.stringify($scope.voteRequest));
                        var myInput = JSON.stringify($scope.voteRequest);
                        alert(myInput);
                        // VoteService.insertRequest($scope.voteRequest).then(function ($scope, status) {
                           VoteService.insertRequest().then(function (data, status, headers, config) {
                         
                        if (status = 0) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    }  
                    }));
                }
            };

         

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
             
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);
                    
                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
               // $http.post("/API/quick-survey/api/Vote/AddVote", $scope.voteRequest).then(function ($scope, data, status, headers, config) {
                $http.post("/API/quick-survey/api/Vote/AddVote", JSON.stringify($scope.voteRequest)).then(function (data, status, headers, config) { 
                //$http.post("/API/quick-survey/api/Vote/AddVote", myInput).then(function (data, status, headers, config) {
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                    alert('success')
                }, function (data, status, headers, config) {
                    alert('error')
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                    isAlreadyvoted = data.isAlreadyvoted;
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {

                $routeProvider
                    .when("/alreadyvoted", {
                        templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                    })

                    .when("/addvote", {
                        templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                    })

                    .when("/", {
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                        controller: "VoteCtrl",
                        // it's is good to download the data before displaying the template without the data
                        // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                        resolve: {
                            qa: ["VoteService", "$route", function (VoteService, $route) {
                                return VoteService.pageInit();
                            }]
                        }

                    }).



               otherwise({
                   redirectTo: '/'
               });
            }]);
        </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

addVoteErroe.png
stop using $scope in service, it's almost a nonsense in angular world

a service receive parameter, for example : questionID, username, answerId or complete JSON structure to play with

try the latest code provided and let me know what error you get, I've none on my side
just not sure what a post to this "/API/quick-survey/api/Vote/AddVote" return
also what parameters this call need to receive to instert succesfully and what did it return
It should return success  which indicates a successful add vote and display addvote.html

which should contain add details which I haven't gotten to yet.

I'll give it a go based on your last comment.
I get a strange error message for post.
I hard coded parameters for testing.
I know I'm there because I get the InRequest alert
I cleaned up the code  little
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="http://home-dev.kmhp.com/global/js/AngularJS/angularjs.min.1.7.5.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular-route.min.js"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />



    <script type="text/javascript">
        // app
        var app = angular.module('quickSurveyApp', ["ngRoute"]);
      

        // controller(s)
        //app.controller("VoteCtrl", ["$scope", "qa", "$location", function ($scope, qa, $location) {
        app.controller("VoteCtrl", ["$scope", "qa", "$location", "VoteService", function ($scope, qa, $location, VoteService) {
            function SetCookiesForDebugging() {
                var thecookie = "departid=351&jobtitle=Digital+Developer&floor=0&username=ij25405&ps%5Fdeptname=Digital+Experience&ps%5Fdeptid=351&cost%5Fcenter=351&birthday%5Fday=16&birthday=0&fsla=&nbsp&psdeptname=Digital+Experience&managerwholename=Lawrence+Raffel&area=215&mailstop=%2D+None+Selected+%2D&managerid=21286&departmentid=0&extension=2158635597&emplid=ij25405&managerusername=LR22638&deptname=KY+Exec+Dir&cubeoffice%5Fno=+&ismanager=0&email=ijohnson%40amerihealthcaritas%2Ecom&lob=1&fname=Isaacy&is%5Fuserlive=1&psdeptid=351&url=%23&costcenter=351&lname=Johnson&company=KEY&managerphone=2159378142&is%5Fmanager=0&wholename=Isaac+Johnson&id=13332&building=0&guest="
                document.cookie = thecookie;
            }
            // sets all scope variables based on associate cookie information.
            function SetUser($scope) {

                //Set User Information with Cookie data
                $scope.IsManager = document.cookie.ismanager;
                $scope.UserId = document.cookie.userName;
                $scope.FirstName = document.cookie.fname;
                $scope.LastName = document.cookie.lname;
                $scope.EmailAddress = document.cookie.email;
                $scope.UserName = document.cookie.username;
            }
            SetCookiesForDebugging();
            
            SetUser($scope);
            
            addAscVote = {
                questionValue: 866,
                answerValue: 4454,
                userNm: 'ij25405'

            }

            $scope.voteRequest =  {
                QuestionNum: 866,                    
                aId: 4454,
                userIn: "ij25405",
                            
            }
            $scope.handleAnswerRadioClick = function (data) {
                $scope.voteRequest.QuestionId = data.QuestionId;
                //$scope.voteRequest.Id = data.Id;
                $scope.voteRequest.Id = Answer.Id
                $scope.voteRequest.AnswerText = data.AnswerText;
                
                //$scope.voteRequest.QuestionText = data.QuestionText
            };
            $scope.activeQuestions = qa.activeQuestions;

            $scope.records = qa.records;
            $scope.QuestionId = qa[0].QuestionId;
            $scope.QuestionText = qa[0].QuestionText;
            $scope.AnswerText = qa[0].AnswerText;
            $scope.Answers = qa[0].Answers;
            var isAlreadyvoted = 0;
            $scope.error = false;
            $scope.AddVote = function () {
                //$scope.error = !!$scope.answer;
                if ($scope.Answer == undefined)
                    $scope.error = true;
                else {
                    $scope.error = false;
                    if (VoteService.getUserVoteCount().then(function (isAlreadyvoted) {
                     
                        if (isAlreadyvoted > 0)
                            $location.path("/alreadyvoted");
                    else {
                        
                        questionValue = 866;
                        alert(questionValue)
                        answerValue = 4454
                        alert(answerValue)
                        userNm = "ij25405"
                        alert(userNm)
                        alert(addAscVote);
                        // VoteService.insertRequest($scope.voteRequest).then(function ($scope, status) {
                           VoteService.insertRequest().then(function (data, status, headers, config) {
                         
                        if (status = 0) //let's say status return true/1 or false/0 to know if the service successfuly saved     
                           $location.path("/addvote"); // I believe the page name is not very nice, should be something like /thankyouforvoting
                    });
                    }  
                    }));
                }
            };

         

        }]);

        // service(s)
        app.factory("VoteService", ["$http", "$q", function ($http, $q) {

            var service = {};
            //Gets all data for page.
            var questionNumber = 0;
             
            service.pageInit = function () {
                var deferred = $q.defer();

                $http.get('/API/quick-survey/api/Question/GetQuestionsByZone/0').then(function (response) {
                    deferred.resolve(response.data);
                    //if (response.data)
                        //alert("success")
                }, function (error) {
                    console.error(error);
                    deferred.reject("error");
                });
                return deferred.promise;
            };
            // inserts new request
            service.insertRequest = function () {
                var deferred = $q.defer();
                alert("InRequest");
                $http.post("/API/quick-survey/api/Vote/AddVote", JSON.stringify(addAscVote)).then(function (response) {
                 
                    deferred.resolve(data); // you should send back something usefull like : {"success":true}
                    console.log("success");
                    alert('success')
                }, function (data, status, headers, config) {
                    alert('error')
                    console.log("error!");
                    console.log(data);
                    deferred.reject("error");
                    
                });
                return deferred.promise;
            };
            // checks if user already voted for a question
            // get true or false
            service.getUserVoteCount = function () {
                var deferred = $q.defer();
                $http.get("/API/quick-survey/api/Vote/GetUserVoteCount/866/ij25405").then(function (data) {
                    isAlreadyvoted = data.isAlreadyvoted;
                    deferred.resolve(data);
                }, function (data, status, headers, config) {
                    
                    console.log(status);
                    deferred.reject("error");
                });
                return deferred.promise;
            };

            return service;
        }]);


            // route(s)
            app.config(["$routeProvider", function ($routeProvider) {

                $routeProvider
                    .when("/alreadyvoted", {
                        templateUrl: "/api-test-pages/Quick-Survey/alreadyvoted.html",
                    })

                    .when("/addvote", {
                        templateUrl: "/api-test-pages/Quick-Survey/addvote.html",
                    })

                    .when("/", {
                        templateUrl: "/api-test-pages/Quick-Survey/survey.html",

                        controller: "VoteCtrl",
                        // it's is good to download the data before displaying the template without the data
                        // so all we found in resolve is gonna be "resolved" before display the page and running the controller
                        resolve: {
                            qa: ["VoteService", "$route", function (VoteService, $route) {
                                return VoteService.pageInit();
                            }]
                        }

                    }).



               otherwise({
                   redirectTo: '/'
               });
            }]);
        </script>


</head>
<body ng-app="quickSurveyApp">
    <div>
        <h1>Quick Survey</h1>
        <div ng-view></div>
    </div>
</body>
</html>

Open in new window

SaysGetforPost.png
post chrome debug, not browser message please
the network tab + console
also I don't recognize the code I provided...
I did not get code.  I got your comment but no code
unless I overlooked.
Console.png
Network.png
Any more thoughts on addvote insertion?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's it.  Thanks again for your valued assistance.

Isaac