Join the Stack Overflow Community
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have login popup and reset password popup in home page. when i click login submit, i will get success ,after success i am calling user api request in success callback, so i will get the user details in template after login success, so it will load the user name in html template, but not from the reset password popup.
in Reset password popup , i have login button, after successfully resets the password. after clicking login button, i am getting success, the console.log inside success callback is showing in console. Since i am calling user api request on success, i am also getting user details in console.log. But the user details is not loading in html template. but after reloading the page, i am getting the user details in html template. I am getting user details, without reload in login popup directly. but not when i reset password and login .
I have the routing like this

 .state('resetPassword', {
                url: '/home/reset_password',
                templateUrl: 'home/home.html',
                controller: 'HomeController',
                controllerAs: 'vm',
                data: {
                    requireLogin: false 
                }
            })
            // UI Router Login
            .state('login', {
                url: '/login',
                templateUrl: 'login/uirouterlogin.html',
                controllerAs: 'vm',
                data: {
                    requireLogin: false 
                }
            })

controller code

through template for parameters i am just passing the resetpassword template and login template. based on which button clicked.

   $scope.showLogin = function(e, template) {
        console.log(template);
        var modalInstance = $uibModal.open({
            animation: true,
            templateUrl: 'login/' + template + '.html',
            'controllerAs': 'login',
            controller: function($uibModalInstance, $scope, logIn) {
                $scope.modalClose = function() {
                    $uibModalInstance.dismiss('Close');
                };
                $scope.loginUser = function(existinguser) {
                    $scope.loginLoading = true;
                    logIn.getlogIn(existinguser)
                        .then(function(success) {
                            $state.reload();
                            $uibModalInstance.dismiss('Close');
                            getApi();  //to get the user details.

                            cartReload();
                            $scope.loginLoading = false;
                            console.log(success.data);
                            $login.getLoginRedirect();
                            $authentication.setAuthKey("key");
                            $scope.loginupError = false;
                        }, function(error) {
                            $scope.loginLoading = false;
                            console.log("Login Failed");
                            $scope.loginError = true;
                            if (error.data) {
                                $scope.loginErrorMsg = error.data.message;
                            } else {
                                $scope.loginErrorMsg = "Error connection, Please try again";
                            }
                            $timeout(function() {
                                $scope.loginError = false;
                            }, 4000);
                        })
                };

*the reset password popup will appears on page load to get that popup i am doing like this *

 $rootScope.$on('$stateChangeSuccess',
        function(event, toState, toParams, fromState, fromParams) {
            if (toState.name === 'resetPassword') {
                $scope.showLogin('$event', 'resetpassword');
            }
            $scope.home_state = toState.name;
        }
    )

html

 <li ng-if="!user"><a ng-click="showLogin($event,'login')">LOGIN</a></li>
<li ng-if="user">user.name</li>
share|improve this question

You are not assigning success.data to the $scope. I think your code should be like this - Controller :

$scope.UserData = success.data;

and from the view/Html :

<li ng-if="!UserData.user"><a ng-click="showLogin($event,'login')">LOGIN</a></li>
<li ng-if="UserData.user">{{UserData.user.name}}</li>
share|improve this answer
    
that is not the issue, i am assigning the success data, i am getting the user details, in direct login popup in home page, but not after reset password-->login success, i am using the same function. no dfferent function – codelearner Aug 10 at 17:58
    
Okay, then define an empty user model. After successful login push the userdata into that model and bind it to the view, that's all. This approach is followed by almost all good developers. – Biswajit Panday Aug 10 at 18:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.