Angular JS: How/when to use ng-click to call a route?

来源:互联网 发布:高铁豪华包厢知乎 编辑:程序博客网 时间:2024/05/07 04:13

http://stackoverflow.com/questions/14201753/angular-js-how-when-to-use-ng-click-to-call-a-route

Routes monitor the $location service and respond to changes in URL (typically through the hash). To "activate" a route, you simply change the URL. The easiest way to do that is with anchor tags.

<a href="#/home">Go Home</a><a href="#/about">Go to About></a>

Nothing more complicated is needed. If, however, you must do this from code, the proper way is by using the $location service yourself:

$scope.go = function ( path ) {  $location.path( path );};

Which, for example, a button could trigger:

<button ng-click="go('/home')"></button>

0 0