검증 예제
검증 예제
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<h2>Validation Example</h2>
<form ng-app="myApp" ng-controller="validateCtrl"
name="myForm" novalidate>
<p>Username:<br>
<input type="text" name="user" ng-model="user" required>
<span style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
<span ng-show="myForm.user.$error.required">Username is required.</span>
</span>
</p>
<p>Email:<br>
<input type="email" name="email" ng-model="email" required>
<span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
<span ng-show="myForm.email.$error.required">Email is required.</span>
<span ng-show="myForm.email.$error.email">Invalid email address.</span>
</span>
</p>
<p>
<input type="submit"
ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||
myForm.email.$dirty && myForm.email.$invalid">
</p>
</form>
<script>
var app = angular.module('myApp', []);
app.controller('validateCtrl', function($scope) {
$scope.user = 'John Doe';
$scope.email = 'john.doe@gmail.com';
});
</script>
</body>
</html>
HTML 양식 속성 인 novalidate 는 기본 브라우저 유효성 검증을 사용 불가능하게하는 데 사용됩니다.
예제 설명
AngularJS 지시어 ng-model 은 입력 요소를 모델에 바인딩합니다.
모델 객체에는 사용자 와 전자 메일 이라는 두 가지 속성이 있습니다.
ng-show 때문에 사용자 또는 전자 메일이 $ dirty 및 $ invalid 인 경우에만 color : red가 표시됩니다 .
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<h2>Validation Example</h2>
<form ng-app="myApp" ng-controller="validateCtrl"
name="myForm" novalidate>
<p>Username:<br>
<input type="text" name="user" ng-model="user" required>
<span style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
<span ng-show="myForm.user.$error.required">Username is required.</span>
</span>
</p>
<p>Email:<br>
<input type="email" name="email" ng-model="email" required>
<span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
<span ng-show="myForm.email.$error.required">Email is required.</span>
<span ng-show="myForm.email.$error.email">Invalid email address.</span>
</span>
</p>
<p>
<input type="submit"
ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||
myForm.email.$dirty && myForm.email.$invalid">
</p>
</form>
<script>
var app = angular.module('myApp', []);
app.controller('validateCtrl', function($scope) {
$scope.user = 'John Doe';
$scope.email = 'john.doe@gmail.com';
});
</script>
</body>
</html>
HTML 양식 속성 인 novalidate 는 기본 브라우저 유효성 검증을 사용 불가능하게하는 데 사용됩니다.
예제 설명
AngularJS 지시어 ng-model 은 입력 요소를 모델에 바인딩합니다.
모델 객체에는 사용자 와 전자 메일 이라는 두 가지 속성이 있습니다.
ng-show 때문에 사용자 또는 전자 메일이 $ dirty 및 $ invalid 인 경우에만 color : red가 표시됩니다 .
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 178 | AngularJS | 8년 전 | 1419 | ||
| 177 | AngularJS | 8년 전 | 1194 | ||
| 176 | AngularJS | 8년 전 | 1270 | ||
| 175 | AngularJS | 8년 전 | 1362 | ||
| 174 | AngularJS | 8년 전 | 1134 | ||
| 173 | AngularJS | 8년 전 | 1875 | ||
| 172 | AngularJS | 8년 전 | 1430 | ||
| 171 | AngularJS | 8년 전 | 1126 | ||
| 170 | AngularJS | 8년 전 | 1389 | ||
| 169 | AngularJS | 8년 전 | 1185 | ||
| 168 | AngularJS | 8년 전 | 998 | ||
| 167 | AngularJS | 8년 전 | 1960 | ||
| 166 | AngularJS | 8년 전 | 1034 | ||
| 165 | AngularJS | 8년 전 | 1096 | ||
| 164 | AngularJS | 8년 전 | 1299 | ||
| 163 | AngularJS | 8년 전 | 1142 | ||
| 162 | AngularJS | 8년 전 | 1358 | ||
| 161 | AngularJS | 8년 전 | 1366 | ||
| 160 | AngularJS | 8년 전 | 1119 | ||
| 159 | AngularJS | 8년 전 | 1083 | ||
| 158 | AngularJS | 8년 전 | 1494 | ||
| 157 | AngularJS | 8년 전 | 1469 | ||
| 156 | AngularJS | 8년 전 | 1315 | ||
| 155 | AngularJS | 8년 전 | 1208 | ||
| 154 | AngularJS | 8년 전 | 1605 | ||
| 153 | AngularJS | 8년 전 | 1069 | ||
| 152 | AngularJS | 8년 전 | 1475 | ||
| 151 | AngularJS | 8년 전 | 1406 | ||
| 150 | AngularJS | 8년 전 | 1102 | ||
| 149 | AngularJS | 8년 전 | 1635 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기