When user has enter correct username and password I want redirect to another location. But when I used $location.path('dashboard')
here then URL of browser is changed but that page not loaded.when refresh I page using ctrl+R or click on refresh icon of browser then appropriate page is loaded.
$http.post('/login', $scope.userInfo)
.success(function (data) {
//Check if the authentication was a success or a failure
//Successful POST here does not indicate success of authentication
if (data.status === "authentication success") {
//Proceed to load the dashboard for the user
$location.path('/dashboard');
} else if (data.status === "authentication error") {
//Inform user of the error
$scope.errorMessage = data.error;
$scope.showErrorMessage = true;
}
})
.error(function (error) {
$scope.errorMessage = "Error while attempting to authenticate. Check log.";
$scope.showErrorMessage = true;
});
};
}]);
In HTML5 mode, the $location service getters and setters interact with the browser URL address through the HTML5 history API. This allows for use of regular URL path and search segments, instead of their hashbang equivalents.
If the user is maximizing it the first time, share the url to this maximized view with the maximizedWidgetId on the UI. As long as you use $location(which is just a wrapper over native location object) to update the path it will refresh the view. Not only $location will refresh the view.
Overview. The $location service parses the URL in the browser address bar (based on the window. location) and makes the URL available to your application. Changes to the URL in the address bar are reflected into $location service and changes to $location are reflected into the browser address bar.
Have you tried using $scope.$apply after that? eg.:
if(!$scope.$$phase) $scope.$apply()
This short method comes in handy quite often as well:
https://github.com/yearofmoo/AngularJS-Scope.SafeApply
To quote https://docs.angularjs.org/guide/$location
"The $location service allows you to change only the URL; it does not allow you to reload the page. When you need to change the URL and reload the page or navigate to a different page, please use a lower level API, $window.location.href."
So, for example, instead of using: $location.path("/path/to/something");
Use this: $window.location.href = "/path/to/something";
$window.location.href
will change the URL AND load the new page.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With