Http calls are happening twice in angular.js
<p>Possible Duplicate of <a href="https://stackoverflow.com/questions/39868079/http-is-getting-called-multiple-times-in-angularjs#">$http is getting called multiple times in AngularJS</a></p>

<p>Sorry I didn't have 50 reputations to comment on the same post.
We are calling the api's using http service and all the services have session id that been passed through cookiestore value.  The api call doesn't work for first time as session id is null during first call and it works only for the second call. </p>

<p>Can anyone help us with this. We have multiple api's and all are happening twice which is actually increasing the load. And yes we have researched it.</p>

<h2>Router.js</h2>

<pre><code>    angular.module('adminsuite',['ngFileUpload','ui.router','ngCookies','angular-clipboard','ngAnimate', 'ngSanitize', 'ui.bootstrap','ngMessages']).constant("__env",env).config(function($stateProvider, $urlRouterProvider, $locationProvider) {

$urlRouterProvider.otherwise('/');
//$locationProvider.html5Mode(true);
$stateProvider
    .state('login', {
        url: '/',
        views:{
            header:{
                templateUrl: '',
                controller: ''
            },
            pageContent:{
                templateUrl: 'Login/login3.html',
                controller: 'loginController'
            },
            footer:{
                templateUrl: 'common/footer3.html',
                controller: 'footerController'
            }
        }



    })

    // HOME STATES AND NESTED VIEWS ========================================
    .state('dashboard', {
        url: '/dashboard',
        views:{
            header:{
                templateUrl: 'common/header.html',
                controller: 'headerController'
            },
            pageContent:{
                templateUrl: 'dashboard/dashboard.html',
                  controller: 'dashboardController'
            },
            footer:{
                templateUrl: 'common/innerFooter.html',
                controller: 'footerController'
            }
        }
    })
    //SURVEY STATES
    .state('survey', {
        url: '/survey',
        views:{
            header:{
                templateUrl: 'common/headerTool.html',
                controller: 'headerController'
            },
            pageContent:{
                templateUrl: 'survey/survey.html',
                  controller: 'surveyController'
            },
            footer:{
                templateUrl: 'common/innerFooter.html',
                controller: ''
            }
        }
    });

    // ABOUT PAGE AND MULTIPLE NAMED VIEWS =================================

 })
</code></pre>

<h2>LoginAuthenticationService.js</h2>

<pre><code>UserService.GetByUsername(requestData)
            .then(function (user) {
                console.log(user);
                if (user.SessionID) {
                   sessionID = user.SessionID;
                   userDetails = user.UserProfile;
                   response = { success: true};
                } else {
                    response = { success: false, message: 'Username or password is incorrect' };
                }
                callback(response);
            });
</code></pre>

<p>UserService.js</p>

<pre><code>function GetByUsername(user) {
    //console.log(__env.apiUrl);
    return $http.post(__env.apiUrl+'/UserAuthentication/login',  user, {headers: { 'Content-Type': 'application/json'}}).then(handleSuccess, handleError('Error getting user by username'));
}
</code></pre>

<h2>Api.js</h2>

<pre><code> $http.get(__env.apiUrl+'/UserSurvey/GetAllSurveys',  {
                            headers: { 'Content-Type': 'application/json','SessionID':$rootScope.token}
                                })
                .then(function(response){
                        console.log(response);
                            return response.data;
                        }, function(error){
                             console.log("error");
                              console.log(error);
                            return error;
                        });
</code></pre>

<p>Any help appreciated.</p>