【问题标题】:Angular ng-hide doesn't work角 ng-hide 不起作用
【发布时间】: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-appng-controllerng-hide就没有任何意义。
  • 另外,查看ng-model 指令。在这里阅读:angularJS doc on Forms。再试一次。 GL!
  • 还有一件事:使用此页面顶部的 SO 搜索框 - 它非常有用 - 搜索类似于 [angularjs] form hide pristine 的内容,您一定会找到类似的问题/答案。如果您找到解决方案,请将您的答案作为可能的解决方案发布,阅读meta: etiquette-for-answering-your-own-question

标签: angularjs ng-hide


【解决方案1】:

我发现了问题。显然是因为没有为表单字段定义 ng-model。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-29
    • 2019-08-07
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多