简体   繁体   English

页面刷新后,注册按钮消失

[英]sign up button disappear after page refreshing

I have problem with sign up button while registering as user, Actually there is check box for T&c. 我注册为用户时注册按钮有问题,实际上有T&c复选框。 After checking that check box only button should enable. 选中该复选框后,仅应启用按钮。 Everything is going well But, when I am refreshing page I am not able to see button, I able to see all other elements even check box. 一切进展顺利但是,当我刷新页面时,我看不到按钮,甚至复选框也看不到其他所有元素。 here are Html tags I used for check box and Sign Up button and I also used flags. 这是我用于复选框和“注册”按钮的Html标签,还使用了标志。

<p class="terms"> <div class="chckbx-cntnr zeromargin" style = "padding:2px;vertical-align:middle"><input type="checkbox" id="rd" name="check" class="flashadmin" ng-model="user.tnc" ng-click="setbuttonFlag(user.tnc)" class="flashadmin"><label class="cstmchk_lbladmin" for="rd"></label></div>
           I agree to the <a href="#!terms_conditions" target="_blank">Terms of Use</a> and <a href="#!privacy_policy" target="_blank">Privacy Policy</a>.</p>

<button ng-if="buttonFlag==true" id="signup"class="btn btn-default btn-block btn-login" type="submit" >Sign up</button> <button ng-if="buttonFlag==false" id="signup" class="btn btn-default btn-block btn-login" disabled >Sign up</button>

here is validation i wrote for flag 这是我为旗帜写的验证

$scope.buttonFlag=false;
$scope.setbuttonFlag =function(checkbox){
    if(checkbox == true){
        $scope.buttonFlag=true;
    }else{
        $scope.buttonFlag=false;
    }
};

I am getting in console Error: $injector:unpr Unknown Provider 我进入控制台错误:$ injector:unpr未知提供程序

First thing is your code looks clumsy! 第一件事是您的代码看起来笨拙!

Below mistake you did, you misunderstood the concept completely. 犯了错误之后,您就完全误解了这个概念。

Why you required for two submit button in your html? 为什么您需要在HTML中添加两个提交按钮? Also no need separate click event for changing button flag. 同样,无需单独单击事件即可更改按钮标志。

Now coming to your question: 现在来问你的问题:

When I am refreshing page I am not able to see button 当我刷新页面时,我看不到按钮

This is because your are using ng-if directive in button element at the same time while initiating your controller you set $scope.buttonFlag=false so obviously you can't see button while refresh.. 这是因为您在初始化控制器时同时在按钮元素中使用ng-if指令,因此您设置了$scope.buttonFlag=false因此显然刷新时看不到按钮。

Below snippet will work for you! 以下代码段将为您服务!

 angular.module("app", []).controller("testCtrl", function($scope) { $scope.buttonFlag = false; }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script> <div ng-app="app"> <div ng-controller="testCtrl"> <input type="checkbox" ng-model='buttonFlag'> I agree to the Terms of Use and Privacy Policy. <button ng-disabled='!buttonFlag' id="signup" class="btn btn-default btn-block btn-login">Sign up</button> </div> </div> 

Well upon refresh you are manually setting buttonFlag to false hence the button disappears.Store buttonFlag in localStorage and check the state of buttonFlag unlike setting it to false as you have done. 好吧,刷新后您手动将buttonFlag设置为false,因此按钮消失了。将buttonFlag存储在localStorage中并检查buttonFlag的状态,这与您将其设置为false不同。

if(localStorage.getItem('buttonFlag')){
    buttonFlag = localStorage.getItem('buttonFlag');
}
else{
    buttonFlag = false;
}

also instead of using two different button for signup use ng-disabled to disable or enable a button 也可以使用ng-disabled禁用或启用按钮,而不是使用两个不同的按钮进行注册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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