AngularJs Change Url

AngularJs Change Url – Sometimes we need to change the url in angularjs. You can use $location.url to redirect from one page to another page. Here in this tutorial we are going to explain how you can redirect in angularjs. You can use our online editor to edit and run the code online.

AngularJs Change Url

You can change the current using the following syntax-

AngularJs Change Url Example:

var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope,$location) {
$scope.changeUrl = function(userId) {
	 // will change the current url to

$location.url(‘/User/’+userId); will set the current url to the new url example – You can call the function – changeUrl(userId) on button click.

Note : Make Sure the service $location is imported before using it.


Add Comment

📖 Read More