且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

角JS:如何/何时使用NG-点击呼叫路由?

更新时间:2023-01-11 16:02:41

路由监控 $位置服务和变化作出反应的URL(通常是通过哈希)。 激活的路线,只需更改URL。要做到这一点最简单的方法是用锚标记。

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>

需要没有什么更复杂。但是,如果你必须这样做从code,正确的方法是使用 $位置服务:

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

其中,例如,一个按钮可以触发

Which, for example, a button could trigger:

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