문제

나는 양식 페이지에 사용되는 모두를 추가하고 편집 형태입니다.그래서 시간에 추가로 데이터를 형성,나를 확인해야 입력 데이터를 복제하거나지 않은,그래서 내가 만들어 지는 것으로 확인 데이터베이스 날씨는 데이터가 존재하지 않습니다.

<input name="divId" type="text" class="form-control fL w250"   ng-model="divisionData.DivisionID"  ng-disabled="Disabled()" unique-divid required /></div>

시 추가하는 새로운 데이터는 그것의 잘 작동합니다.하지만 시간의 편집도를 사용하여 동일한 형태로도 독특한-divid 지시어가 실행되고 있습니다.나는 원하지 않는 이런 일이 편집 페이지

.directive('uniqueDivid', function($http) {
  var toId;
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function(scope, elem, attr, ctrl) { 
     scope.$watch(attr.ngModel, function(value) {
        if(toId) clearTimeout(toId);
        toId = setTimeout(function(){
          console.log(value);
            $http({
            method  : 'POST',
            url     : 'http://testurl',
            data    : $.param({'DivisionID' : value}), 
            headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  
        })
            .success(function(data) {
                console.log(data);
                if(data.status == 'success'){
                    ctrl.$setValidity('uniqueDivid', true);
                }else if(data.status == 'fail'){
                    ctrl.$setValidity('uniqueDivid', false);
                }
                if (!data.success) {
                } else {
                }
            });


        }, 200);
      })
    }
  }
});

십시오 솔루션을 제안 사용하지 않거나 지시하거나 정지한 범위.$시계 기능에서 시간의 편집합니다.

도움이 되었습니까?

해결책

할 수 있 추가적인 특성을 입력 필드를 나타내는 유형의 형태로 작업(생성/수정)봉사하고 있는?

예를 들어:

<input name="divId" type="text" class="form-control fL w250" ng-model="divisionData.DivisionID" ng-disabled="Disabled()" unique-divid form-action="edit" required />

면 작업 유형과 일치하는지 그냥 돌아서 연결하는 기능입니다.

link: function(scope, elem, attr, ctrl) { 
  if (attr.formAction === "edit") return;
  ..
}

는 경우에 당신을 원하지 않을 수정 템플릿 무엇입시에서 컨트롤러 또는 범위에 사용할 수 있는 사이 구별 새로운 기존하는 divisionData?당신이 사용할 수 있는 속성으로 국기를 반환에서 unique-divid directive:

link: function(scope, elem, attr, ctrl) { 
  if (!scope.divisionData.isNew) return;
  ..
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top