2014-12-15 4 views
6

필드 유효성 검사가 포함 된 간단한 페이지가 있습니다. employee.html 필드의 유효성을 검사하지만 동일한 코드를 추가하고 ng- 유효성 검사가유효 숫자가 포함 된 경우 유효성 검사가 작동하지 않습니다.

without ng-include 유효성 검사를 작동하지 않는 포함하여 작동합니다

DAS :

<form name="form" class="form-horizontal" ng-validate="create(data)" novalidate> 
    <div class="row"> 
     <div class="col-xs-6"> 
      <div class="form-group"> 
       <label for="" class="col-xs-6 control-label">First Name:</label> 
        <div class="col-xs-6"> 
        <input name="first_name" type="text" class="form-control" ng-model="data.first_name" placeholder="First name" ng-required="true"> 
         <div class="alert alert-danger" ng-show="form.$submitted && form.first_name.$error.required">Enter first name.</div> 
        </div> 
      </div> 
     </div> 
    </div> 
</form> 

with ng-include 유효성을하지 작업을 수행 hboard.html

<div class="container"> 
    .................... 
    .................. 
    <ng-include src="employee.html"></ng-include>   
</div> 

내 질문은 : 어떻게 유효성 검사가 NG-포함 내에서 작동 할 수 있습니까?

+1

'ng-include'는 자체 범위를 생성한다는 사실과 관련이 있다고 생각합니다.하지만 더 많은 컨텍스트가 필요합니다 (바이올린은 훌륭합니다). – Rasalom

+0

유효성 검사가 작동하지 않는 유일한 방법입니까? –

+0

네 유효성 검사가 작동하지 않는 유일한 것 –

답변

0

$submitted이 작동하지 않습니다. angular version 1.3. 양식 만 제출하는 경우 메시지를 표시해야하는 경우 양식을 제출했는지 여부를 감지 할 수있는 변수를 보관할 수 있습니다.

유효성 검사 메시지를 사용 formSubmitted 대신 여기 $submitted

<div class="alert alert-danger" ng-show="formSubmitted && form.first_name.$error.required">E.. 

의에서 컨트롤러 테스트 기능

$scope.create = function(data) { 
    $scope.formSubmitted = true; 
} 

에서

가 작동하고 있음을 수행하는 Plunker


,

하지만 당신은

각 각 1.3.x 버전에서 $submitted을 소개하고이 문제를 해결할 각도를 업그레이드하는 이전의 각 버전으로 시도 될 수있다 각도 1.3 이상 버전을 사용하는 경우. 여기

Changes of the 1.3합니다 -

새로운 기능을 확인하십시오 : 형태 여기

<div class="alert alert-danger" ng-show="form.$submitted && form.first_name.$error.required">Enter first name.</div> 

에 새로운 $ 제출 된 상태를 추가 plunker

+0

내가 당신을 업데이트하려고합니다. –

+0

@AbuHamzah 제 대답을 업데이트 해주세요 :) –

+0

'AngularJS v1.2.23'을 사용하고 있습니다 ... 걸릴 것입니다 좀 더 자세히보기 –

0
당신은 부트 스트랩을 사용할 수 있습니다

하고있다 그와 같은 검증은

<form name="personalinformation"> 

<label for="fname"> First Name<span style="color:red" ng-show="personalinformation.firstname.$error.required">*</span></label> 
<input type="text" class="form-control" id="" placeholder="First Name" ng-model="PerInfo.FirstName" required name="firstname"> 

</form> 

당신은 당신이 validationFunction 만들 수있는 각도로 검증 거짓은 다음 = "true"로

0
NG-쇼에 값을 입력 살았어입니다 controller.If 입력 유형의 텍스트 또는 다른 요소의 값을 전달 NG를 클릭하면

대신 <ng-form></ng-form>을 사용하십시오.

관련 문제