当我给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>
&#13;
答案 0 :(得分:1)
您需要为表单使用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>
答案 1 :(得分:0)
您的代码段有语法错误,修复错误后的确切代码段正在运行。
var app = angular.module('myApp', []);
&#13;
<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>
&#13;