Angularjs ng-click 在秒点击时重定向

Angularjs ng-click redirects on seconds click

为什么我的 ng-click 仅在第二次点击时重定向到新位置?

它应该被重定向到 $location.path('/login.signin'); 但是只有当我再次点击按钮时它才会这样做。奇怪的。这是从哪里来的?

这是我的 HTML:

<div class="box-forgot" ng-controller="ResetPass">
    <form class="form-forgot" name="resetpassword">
        <fieldset>
            <legend>
                Reset Password:
            </legend>
            <p>
                Enter your new password below to reset the old password:
            </p>
            <div class="form-group">
                <span class="input-icon">
                    <input type="password" class="form-control" id="password" ng-model="user.password" ng-minlength="8" name="password" placeholder="Password" required="">
                    <i class="fa fa-lock"></i> </span>
                <p class="help-block" ng-show="registration.password.$dirty && registration.password.$error.minlength">Too short! </p>

            </div>
            <div class="form-actions">
                <button class="btn btn-primary pull-right" ng-disabled="resetpassword.$invalid" ng-click="resetMe()">
                    Reset <i class="fa fa-arrow-circle-right"></i>
                </button>
            </div>
        </fieldset>
    </form>
</div>

这是我的控制器:

app.controller("ResetPass", ["$scope","firebase", "$location",
    function ($scope,firebase, $location) {

    $scope.resetMe = function () {
        var newPassword = $scope.user.password;
        var actionCode = $location.search().oobCode;
        var mode = $location.search().mode;
        firebase.auth().confirmPasswordReset(actionCode, newPassword)
            .then(function (resp) {
            console.log("reset pass, done");
            $location.path('/login.signin');
        }).catch(function (error) {
            $scope.errMsg = true;
            $scope.errorMessage = error.message;
        });
    }

}]);

编辑:我不知道如何将此 的答案与我的问题联系起来。

编辑 2:对于 ui 路由器状态,这里是 link

从那个问题来看 - 看起来重要的变化是使用 $state.go('profile', _user ),它是 ui-router 的一部分,而不是 $location.path,但由于这是第三个 -派对库 - 它可能在 angular 的摘要之外被调用。假设您使用的是 ui-router,我会尝试以下操作:将您的呼叫替换为 $state.go('login.signin')

$scope.resetMe = function () {
    var newPassword = $scope.user.password;
    var actionCode = $location.search().oobCode;
    var mode = $location.search().mode;
    firebase.auth().confirmPasswordReset(actionCode, newPassword)
        .then(function (resp) {
        console.log("reset pass, done");
        $location.path('/signin').replace(); // Add this
        $state.go('login.signin'); // and this
    }).catch(function (error) {
        $scope.errMsg = true;
        $scope.errorMessage = error.message;
    });
}

post 的另一个重大变化是他们将对 firebase 的调用封装在一个服务中,并将承诺返回给控制器中的调用。

app.factory("AuthenticationService", ["firebase", function (firebase) {
// Inside your service
   return {
      resetPassword: function(actionCode, newPassword) {
         // return this next line
         return firebase.auth().confirmPasswordReset(actionCode, newPassword)
              .then(function (resp) {
              console.log("reset pass, done");
              return resp; // return the response
          });
      }
   }
}]);

在你的控制器中:

$scope.resetMe = function () {
    var newPassword = $scope.user.password;
    var actionCode = $location.search().oobCode;
    var mode = $location.search().mode;
    AuthenticationService.resetPassword(actionCode, newPassword)
    .then(function (resp) {
        $scope.$apply(function() {
           $location.path('/signin').replace();
           $state.go('login.signin');
        });
    }).catch(function (error) {
        $scope.errMsg = true;
        $scope.errorMessage = error.message;
    });
}