javascript - dynamically change the path of href angular JS -
javascript - dynamically change the path of href angular JS -
i trying alter href value on click of it.
this have tried.
html:
<a href="#page1">demo</a>
js:
angular.config(function ($routeprovider) { $routeprovider .when('/page1', { templateurl: 'main.html' controller: 'firstcontroller' }) .when('/page2', { templateurl: 'sub.html' controller: 'firstcontroller' }) .otherwise('main.html');
how alter path of anchor tag everytime when clicked on it.
can please help me out.
use different controllers each page. can utilize variable link , set in related controller. example:
<a href="#/{{mylink}}">demo</a>
or
<a ng-href="#/{{mylink}}">demo</a>
and in each related controller:
$scope.mylink="page1";
or
$scope.mylink="page2";
etc.
or if insist utilize same controller, can check location path:
if ($location.path().substring(1) == "page1") { $scope.mylink="page2"; }
javascript jquery angularjs angularjs-directive
Comments
Post a Comment