AngularJS ng-hide元素基于Firebase模式

时间:2016-10-10 22:15:22

标签: javascript angularjs firebase firebase-authentication

参考此documentation here,如果控制器功能中的modeverifyEmail,我会尝试隐藏我的元素。没有成功。有人可以帮忙看看它为什么不起作用吗?

我的HTML就像:

<div class="box-forgot" ng-controller="ResetPass">
    <form class="form-forgot" name="resetpassword" ng-hide="mode == 'verifyEmail'">
        <fieldset>
            <legend>
                Reset Password:
            </legend>

            <div class="form-group">
                <span class="input-icon">
                    <input type="password" class="form-control" id="password" ng-model="user.password" name="password" placeholder="Password" required="">
                    <i class="fa fa-lock"></i> </span>

            </div>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary pull-right" ng-click="resetMe()">
                    Reset
                </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 个答案:

答案 0 :(得分:2)

尝试使用$ scope对象而不是var

绑定模式

而不是

    var mode = $location.search().mode;

这样做

    $scope.mode = $location.search().mode;

答案 1 :(得分:1)

您在HTML中尝试引用的变量不可见,因为它不在控制器的范围内。

你必须改变这个:

var mode = $location.search().mode;

到此:

var mode = $scope.mode = $location.search().mode;
// or
$scope.mode = $location.search().mode;