나는 새로운 각도의 사용자이고 양식에 대한 유효성 검사를 시도하고 있습니다. 여기 예를 발견 http://plnkr.co/edit/gLDFaf?p=previewAngularjs : ng-class 및 양식 유효성 검사
그것은 내가 "엄격한 사용"추가하면 그렇게 검증 (빨간색 테두리) 내 문제 : 내가 이해하지 못하는 어떤 작동하지 않는 이유 ... 원하는 정확히 무엇; script.js
"use strict"; // <-- validation doesn't work if removed
module = angular.module('app', []);
module.controller('NewUserController', function($scope) {
$scope.save = function() {
if ($scope.userForm.$valid) {
alert('User saved');
$scope.reset();
} else {
alert("There are invalid fields");
}
};
$scope.reset = function() {
$scope.user = { name: '', email: '' };
}
});
의 상단과보기에 :
<body ng-app="app" ng-controller="NewUserController">
<h1>Add New User</h1>
<form name="userForm" novalidate>
<div class="form-group" ng-class="{ 'has-error': userForm.name.$invalid }" >
<label class="control-label">Name</label>
<input type="text" class="form-control" name="name" ng-model="user.name" required placeholder="Name" />
</div>
<div class="form-group" ng-class="{ 'has-error': userForm.email.$invalid }" >
<label class="control-label">Email</label>
<input type="email" class="form-control" name="email" ng-model="user.email" required placeholder="Email" />
</div>
<button class="btn btn-primary" ng-click="save()">Add User</button>
<button class="btn btn-link" ng-click="reset()">Reset</button>
</form>
</body>
누군가가 나를 설명 할 수 :)
감사합니다!
plunker 업데이트 완벽한, 덕분에 많은 plunker에 대한 – Julien