帮我看看哪里出错了?
main.js
var app = angular.module("myApp", []);
app .controller('signUpController',function($scope){
$scope.userdata = {};
$scope.submitForm = function(){
console.log($scope.userdata );
if($scope.signUpFrom.$invalid){
alert('请检查你的输入信息!')
}else{
alert('输入正确!')
}
}
})
app .directive('compare', function()
{
var o = {};
o.strict = 'AE';
o.scope ={
orgText:'=compare'
}
o.require = 'ngModel';
o.link = function(sco,ele,att,con){/*主函数*/
con.$validators.compare = function(v){
return v == sco.orgText;
}
sco.watch('orgText',function(){
con.$validate();
});
}
return o;
})
代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>验证规则</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<style type="text/css">
.red{
background: #a30;
}
.error{
color: #a10;
}
input.error{
border: 1px solid #a10;
}
.wrapper{
width: 300px;
margin: 30px auto;
}
</style>
</head>
<body ng-app="myApp" ng-controller="signUpController">
<div class="wrapper">
<h2>注册</h2>
<form name="signUpFrom" ng-submit="submitForm()">
<div class="form-group">
<label> 用户名</label>
<pre>合法:{{signUpFrom.username.$valid}}</pre>
<pre>{{userdata.username}}</pre>
<input
name="username"
type="text"
class="form-control"
ng-model="userdata.username"
ng-minlength="4"
ng-maxlength="10"
required
/>
<p class="error" ng-if="
signUpFrom.username.$error.required
&& signUpFrom.username.$touched">
用户名不可为空
</p>
<p class="error" ng-if="
(signUpFrom.username.$error.minlength
||signUpFrom.username.$error.maxlength)
&& signUpFrom.username.$touched">
用户名长度应该在4到10位
</p>
</div>
<div class="form-group">
<label> 密码</label>
<pre>合法:{{signUpFrom.password.$valid}}</pre>
<pre>{{userdata.password}}</pre>
<input name="password"
type="password"
class="form-control"
ng-model="userdata.password"
ng-minlength="6"
ng-maxlength="255"
required
/>
<p class="error" ng-if="
signUpFrom.password.$error.required &&
signUpFrom.password.$touched">
密码不可为空
</p>
<p class="error" ng-if="
(signUpFrom.password.$error.minlength ||
signUpFrom.password.$error.maxlength )&&
signUpFrom.password.$touched">
密码长度在6位到255之间
</p>
</div>
<div class="form-group">
<label> 确认密码</label>
<pre>合法:{{signUpFrom.password2.$valid}}</pre>
<pre>{{userdata.password2}}</pre>
<input name="password2"
type="password"
class="form-control"
ng-model="userdata.password2"
compare ="userdata.password"
required
/>
<p class="error" ng-if="
signUpFrom.password2.$error.compare &&
signUpFrom.password2.$touched">
俩次密码输入不一致
</p>
</div>
<div class="form-group">
<button class="btn btn-primary">注册</button>
</div>
</form>
</div>
<script src="js/angular.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/main.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
当密码输入达到6位后自动消失了!请大神指点我哪里出错了