how to redirect one html page to another using button click event in angularjs

梦想的初衷 提交于 2019-12-05 10:32:31

In html,

<button ng-click="redirect()">Click</button>

In JS,

$scope.redirect = function(){
  window.location = "#/page.html";
}

Hope it helps.....

Would probably make a small modification.

inject $location and use:

$scope.redirect = function(){
  $location.url('/page.html');
}

The benefits of using $location over window.location can be found in the docs, but here's a summary as of (1.4.x)

https://docs.angularjs.org/guide/$location

If anyone knows how to make this redirect directly from the html in a cleaner way please let me know because I would prefer that sometimes over making a function in the controller...

N.Y. Gudlanur

I have succeeded navigation PAGE with below code in AngularJS.

$scope.click = function ()
{
    window.location = "/Home/Index/";
}

In case you are using material design button 'md-button', you could do this.

I have tried giving attribute href, assigned with the link path. The redirection works well.

This could be tried if it is only redirection and there are no other tasks to be done before redirection.

<test1>
  <md-button href="/page.html">Click</md-button>
</test1>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!