【问题标题】:AngularJS ng-hide element based on Firebase mode基于 Firebase 模式的 AngularJS ng-hide 元素
【发布时间】:2016-10-10 22:15:21
【问题描述】:

参考这个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;
            });
        }
}]);

【问题讨论】:

    标签: javascript angularjs firebase firebase-authentication


    【解决方案1】:

    尝试使用 $scope 对象而不是 var 来绑定模式

    代替

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

    这样做

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

    【讨论】:

    • 在 ng-hide 中你只能访问那些与 $scope 对象绑定的变量
    【解决方案2】:

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

    你必须改变这个:

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

    到这里:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-24
      • 2016-02-05
      • 1970-01-01
      • 2014-12-08
      • 2014-03-27
      • 1970-01-01
      • 2017-08-13
      • 2014-10-14
      相关资源
      最近更新 更多