【发布时间】:2015-05-24 01:24:19
【问题描述】:
我遇到了 Angular 的问题。我的代码很简单,但 ng-hide 不起作用。当用户修改注册表单的按钮时,我想隐藏部分代码。你能帮帮我吗?
<body ng-app="myApp" ng-controller="formCtrl">
<form name="signUpForm" ng-submit="signUpFormSubmit(signUpForm.$valid)" novalidate>
<input type="text" placeholder="Email address *" name="signUpEmail">
<input type="text" placeholder="Pseudo *" name="signUpPseudo">
<input type="password" placeholder="Password *" name="signUpPassword">
<button type="submit" class="button button-block button-positive">Sign Up</button>
<div ng-hide="signUpForm.signUpEmail.$pristine || signUpForm.signUpPseudo.$pristine || signUpForm.signUpPassword.$pristine">
<hr>
<div class="padding-horizontal">
<h4 class="center">You already have an account?</h4>
<button class="button button-block button-stable">Sign In</button>
</div>
</div>
</form>
这是一个 JsFiddle:http://jsfiddle.net/9ce63mno/3/
更新:虽然我不知道为什么在这种情况下需要控制器,但我添加了一个。我还定义了 ng-app。
谢谢
【问题讨论】:
-
demo 没有任何
ng-app...如果没有引导角度,我们应该在那里看到什么? -
请尝试提供更完整、可验证的问题示例。没有
ng-app和ng-controller,ng-hide就没有任何意义。 -
另外,查看
ng-model指令。在这里阅读:angularJS doc on Forms。再试一次。 GL! -
还有一件事:使用此页面顶部的 SO 搜索框 - 它非常有用 - 搜索类似于
[angularjs] form hide pristine的内容,您一定会找到类似的问题/答案。如果您找到解决方案,请将您的答案作为可能的解决方案发布,阅读meta: etiquette-for-answering-your-own-question