简体   繁体   中英

AngularJS ng-hide element based on Firebase mode

Referring to this documentation here , I am trying to hide my element if the mode in the controller function is verifyEmail . No success. Could somebody help to see why it doesn't work?

My HTML is like:

<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>

And the corresponding controller is:

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;
            });
        }
}]);

Try to bind mode with $scope object instead of var

Instead of

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

Do this

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

The variable you're trying to reference in your HTML is not visible because it's not in the controller's scope.

You have to change this:

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

to this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM