gpt4 book ai didi

javascript - angularJS:ng-show 不适用于 ng-app?

转载 作者:行者123 更新时间:2023-12-03 07:06:13 24 4
gpt4 key购买 nike

当我给 ng-app 命名并声明它时,为什么我的 ng-show 不起作用?

https://jsfiddle.net/jzhang172/f7mrkf48/

$(function(){
var app = angular.module('myApp', []);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app="myApp">
<form name="formMe">

1<input type="text"><br>
2<input type="text"><br>
Email<input name="email" ng-model="email" required>

<span ng-show="formMe.email.$touched">You touched me</span><br>
<input type="submit" ng-disabled="formMe.email.$invalid">
</form>

</div>

最佳答案

您需要为表单使用name属性,并使用该表单名称而不是模块名称myApp来验证表单字段。因此,请在表单标记 name="myForm" 中使用 name 属性,并使用 myForm.email.$invalid

进行验证

喜欢:

<form name="myForm">

1<input type="text"><br>
2<input type="text"><br>
Email<input type="email" name="email" ng-model="email" required>

<span ng-show="myForm.email.$touched">You touched me</span><br>
<input type="submit" ng-disabled="myForm.email.$invalid">
</form>

关于javascript - angularJS:ng-show 不适用于 ng-app?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36819270/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com