Question: The code seems simple, but as I read [the docs for $location](https://docs.angularjs.org/guide/$location), I notice there's a LOT of complexity I don't understand. My setup is as follows:

```
// in app.js
$routeProvider.when('/done'     , {templateUrl: 'partials/done.html', controller: 'DoneController'});

// in my controller where $location is injected, on a button press...
if (!$scope.errors.length) {
    $scope.model.save().then(function() {
        alert("did I get here?");
        $location.path('/done');
    });
}

```

I press the button and see the alert, but no change in view. I press the button a second time (saving data to the cloud a second time), I see the alert a second time and the view does change. Any ideas why? Thanks in advance.

Answer: 
I believe there must be something asynchronous in your sequence.
It generally happens when using an external libraries like jQuery.

The problem is that the `$watch -> $digest -> $apply` cycle of angular is not triggered with external libraries events. So the change has been made, but not propagated by angularjs.

Using `$scope.$apply()` will solve your problem

```
if (!$scope.errors.length) {
    $scope.model.save().then(function() {
        alert("did I get here?");
        $scope.$apply(function(){
          $location.path('/done');
        });
    });
}

```
i am not sure why? but this may be your html problem.if your html like this:

```
<a href="#" class="btn" ng-click="myFunction()">submit here</a>

```

then do `href=""` means code should be like this:

```
<a href="" class="btn" ng-click="myFunction()">submit here</a>

```