0

In my code location.path("#/") is not working I had tried a lot but I don't understand why it's not working. There is simple logic that after successful signup popup is close and notification bar plugin will see notification.

I struck in this since 4 hours.

Signup

    (function () {
        'use strict'
        /*
         * Signup Controller
         * @param {$scope} Object
         * @return
         */
        function SignupCtrl($scope, $location, $window, $timeout, UserService, notifications) {
            //$scope.captchaError=false;
            //$scope.passwordPattern = '((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,})';
            $scope.doRegistration = function () {
                console.log("form validation status:" + $scope.frmSignup.$valid);
                if (true === $scope.frmSignup.$valid) {
                    console.log("validation successfully executed");
                    UserService
                            .register($scope.user)
                            .error(function () {
                                angular.element('#btnCancelSignup').triggerHandler('click');
                                notifications.showError({
                                    message: 'Ooops! there is error occured, please try again.',
                                    hideDelay: 1500, //miliseconds
                                    hide: true // boolean
                                });
                                $location.path("#/");
                            })
                            .then(function (res) {
                                if (res.data.status === 1) {
                                    console.log("success in registration");
                                    angular.element('#btnCancelSignup').trigger('click');
                                    notifications.showSuccess({
                                        message: 'Please check your email to complete registration.',
                                        hideDelay: 1500, //miliseconds
                                        hide: true // boolean
                                    });
                                    $location.path("#/");
                                    if(!$scope.$$phase) $scope.$apply();

                                }
                                Recaptcha.reload();
                            });
                }
            }
        }

        angular
                .module('AppWhizbite')
                .controller('SignupCtrl', ['$scope', '$location', '$window', '$timeout', 'UserService', 'notifications', SignupCtrl]);
    }());
Dipak
  • 2,248
  • 4
  • 22
  • 55

2 Answers2

0

Try as following

$scope.$apply(function() { 
  $location.path('/');
});

Here's another post you might read for better understanding Angular $location.path not working

Community
  • 1
  • 1
Ashraful Alam
  • 380
  • 1
  • 12
  • I read and It tried it but it's not working. I applied almost all ways. – Dipak Mar 30 '16 at 16:05
  • Ashraful : I got an error when It tried same code.Error: [$rootScope:inprog] $digest already in progress. I am using stateprovider and I would like to reload entire page. – Dipak Mar 30 '16 at 16:07
  • If you are using $stateProvider (ui-router not ngRoute), your should use replace $location.path('/') with $state.go('/'). Again, you haven't injected and used ngRoute / ui-router as dependency in app.module and controller. Please clarify if you are using ngRoute or ui-router. – Ashraful Alam Mar 30 '16 at 16:19
0

From $location doc:

It does not cause a full page reload when the browser URL is changed. To reload the page after changing the URL, use the lower-level API, $window.location.href.

so, try:

$window.location.href = '/';
thaleshcv
  • 752
  • 3
  • 7