Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular js trigger routing

I have a reset link, which is meant to reset my angular js app...

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

I am handling the button press in the main controller...

$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 = "/#";

    }

}

I am not sure if setting the window.location as I have done is the right way to do things. It works for me, but does not seem like the correct way, and I have not been able to find out ow to do it online.

like image 412
Billy Moon Avatar asked Dec 05 '25 03:12

Billy Moon


1 Answers

I have been using the so-called AngularJS way like this, at least the routing is handled by AngularJS rather than browser directly.

function Ctrl($scope, $location) {

    $scope.resetApp = function(){

        ...

        $location.url('/');
    }
}

The path is what is defined in the Route Provider like this:

app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/', {
            templateUrl: 'index.html',
            controller: 'Ctrl'
        }).
...
like image 54
zs2020 Avatar answered Dec 06 '25 17:12

zs2020



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!