AngularJs reload page


AngularJs reload page- There are many ways to reload the page in AngularJs. You can use location.reload() method to reload the current page. Here in this tutorial we are going to explain how you can reload a page using AngularJs. You can use our online demo try and edit the code online.


AngularJs reload page

You can use location.reload() method to reload the current page. Here is full example –

AngularJs reload page | Example:

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope,$window) {

 $scope.reloadPage = function() {
	 $window.location.reload();
 };
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController"> 
 <button ng-click='reloadPaage()' >Reload Page<button>

</div> 
</div>
</body>  
</html>      

Please make sure you have imported $window service in controller.


Advertisements

Add Comment

📖 Read More