ng-if不起作用
<body>
<style>
* { margin: 0; padding: 0;}
.outDiv {
width:500px;
height:500px;
margin:50px auto;
font-family:"華文楷體";
font-size:25px;
}
p {
margin-left:100px;
}
.null {}
.error {
border:1px solid red;
}
.worry {
font-family:"黑體";
font-size:14px;
color:red;
margin-left:100px;
}
input {
width:300px;
height:30px;
margin:10px 0px 10px 100px;
}
.btn {
width:200px;
height:40px;
background-color:#0F0;
border:1px solid #0C0;
margin-left:160px;
}
</style>
<div class="outDiv" ng-controller="myCtrl">
? ? <form name="addForm" ng-submit="upform()">
? ? ? ? <h2 align="center">用戶注冊</h2><br />
? ? <div>
? ? ? ? ? ? <p>用戶名:</p><input type="text" placeholder="請輸入用戶名" ng-model="username" ng-minlength="4" ng-maxlength="10" required /><br />
? ? ? ? ? ? ? ? <div class="worry" ng-if="addForm.username.$invalid">您輸入有誤請檢查</div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div>
? ? ? ? ? ? <p>密碼:</p><input type="password" placeholder="請輸入密碼" ng-model="password" />
? ? ? ? ? ? </div>
? ? ? ? ? ? <div>
? ? ? ? ? ? <p>確認密碼:</p><input type="password" placeholder="請輸入確認密碼" ng-model="password2" />
? ? ? ? ? ? </div>
? ? ? ? ? ? <div><input type="submit" value="提交" class="btn" /></div>
? ? </form>
? ? </div> ? ?
<script src="js/angular-1.3.0/angular.min.js"></script>
<script>
? ? var app = angular.module('myApp',[]);
app.controller('myCtrl',function($scope){
$scope.upform = function(){
console.log('表單提交了!');
};
});
? ? </script>
</body>
2017-03-01
你有2個錯誤:
1:你沒有在body加 ng-app="myApp" ;
2:<input type="text" placeholder="請輸入用戶名" ng-model="username" ng-minlength="4" ng-maxlength="10" required /> ?這個加上 name="username"