Is there any option to set the page URL dynamically in Angular JS. I know Angular JS popularly known as single page application,where we load the HTML page view and change the data inside the HTML by biding the values.
For example: Say I have a page www.mysite.com/#/myPage here I change the values inside myPage HTML file . i want to change the URL which is getting displayed in the browser based on the content in the page.
<div ng-app ng-controller="LoginController">
<div>Hello {{ user.firstName }}</div>
<input ng-model="user.firstName"></input>
<input type="submit" ng-click="login()" value="Login"></input>
<div ng-repeat="login in logins">{{ login }}</div>
</div>
function LoginController($scope) {
$scope.user = {
firstName: "Foo",
lastName: "Bar"
};
$scope.logins = [];
$scope.login = function () {
$scope.logins.push($scope.user.firstName + " was logged in.");
};
}
Demo link.. https://jsfiddle.net/Lt7aP/4/
Now before I click on the login button, the URL might be like this www.mysite.com/#/myPage and after clicking on login the page URL has to change to something like this www.mysite.com/#/myPageLoggedIN.
Is there any way I can achieve this using angular JS routing or $location service.