Angular js触发器路由

Angular js trigger routing

本文关键字:路由 触发器 js Angular      更新时间:2023-09-26

我有一个重置链接,旨在重置我的angular js应用程序。。。

<a ng-click="resetApp()">reset</a>

我正在处理主控制器中的按钮按下。。。

$scope.resetApp = function(){
    if(confirm("You will lose data...")){
      $scope.user.reset();
      // not sure how to do this in more angular js way
      window.location = "/#";
    }
}

我不确定像我所做的那样设置window.location是否是正确的做事方式。它对我有效,但似乎不是正确的方式,而且我还没能在网上找到如何做到这一点。

我一直在使用所谓的AngularJS方式,至少路由是由AngularJS处理的,而不是直接由浏览器处理的。

function Ctrl($scope, $location) {
    $scope.resetApp = function(){
        ...
        $location.url('/');
    }
}

路径是Route Provider中定义的路径,如下所示:

app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/', {
            templateUrl: 'index.html',
            controller: 'Ctrl'
        }).
...