2016-08-10 3 views
0

이 지시어 :왜 내 지시문이 오류없이 실패합니까?

angular.module('WizmoApp', []) 
    .directive('confirmClick', function() { 
     return { 

       priority: -1, 
       restrict: 'A', 
       link: function(scope, element, attrs){ 
        element.bind('click', function(e){ 
         var message = attrs.ngConfirmClick; 
         // confirm() requires jQuery 
         if(message && !confirm(message)){ 
          //e.stopImmediatePropagation(); 
          //e.preventDefault(); 
         } 
        }); 
       } 
     }; 
    }); 

, 여기에서 전사하기 위해 노력하고있어 : Confirmation dialog on ng-click - AngularJS 가 비명을 지르는 정지에 내 응용 프로그램을 가지고 충분하다. 화면에 아무런 표시도없고, js 오류도없고, 아무런 의미도없고, 단지 빈 사적인 표시입니다.

이것은 내가 그것을 사용하고 방법은 다음과 같습니다 커녕, 지시어를 디버깅하는 방법을

<tr class="" 
    ng-repeat="package in adminManifestVm.Manifest | orderBy:'Id' track by $index" 
    ng-click="adminManifestVm.debinPackage(package.Id);" 
    ng-confirm-click="Are you sure you want to debin this?"> 

어떤 아이디어 하나를 써주세요.

[편집] 예에서 지시문은 실제로 이라는 ngConfirmClick으로 지정되었습니다. 그것을 바꿨지 만 아무런 차이가 없다.

답변

1

당신은 잘못

<tr class="" 
ng-repeat="package in adminManifestVm.Manifest | orderBy:'Id' track by $index" 
ng-click="adminManifestVm.debinPackage(package.Id);" 
confirm-click val="Are you sure you want to debin this?"> 

하고 지시에

이 범위를 해당 솔루션이 작동하지

angular.module('WizmoApp', []) 
.directive('confirmClick', function() { 
    return { 
      scope:{ 
       val: '=' 
      }, 
      priority: -1, 
      restrict: 'A', 
      link: function(scope, element, attrs){ 
       element.bind('click', function(e){ 
        var message = val; 
        // confirm() requires jQuery 
        if(message && !confirm(message)){ 
         //e.stopImmediatePropagation(); 
         //e.preventDefault(); 
        } 
       }); 
      } 
    }; 
}); 
+0

아. 올바른 것으로 검사되지 않은 스 니펫을 복사 할 때 나를 올바르게 지원합니다. 감사합니다. . – DaveC426913

+0

아쉽게도 현재 상태로 작동하지 않습니다. 나는 '예기치 않은 문자열'을 '='또는 '= val이 정의되지 않음'에서 얻습니다. 나는 그것으로 바이올린을 칠 것이다. – DaveC426913

+0

범위를 업데이트했습니다. –

0

를 추가 사용하고 있습니다.

Syntax Error: Token 'Package' is an unexpected token at column 6 of the expression [Move Package back to Pile?] starting at [Package back to Pile?].

이 내가 그것을 구현 한 방법은 다음과 같습니다 :이 오류는 이해되지 않는다

지침 :

(function(){ 
angular 
    .module('WizmoApp') 
    .directive('confirmClick', function() { 
     return { 
      priority: -1, 
      restrict: 'A', 
      link: function(scope, element, attrs){ 
       element.bind('click', function(e){ 
        var message = attrs.val; 
        // confirm() requires jQuery 
        if(message && !confirm(message)){ 
         e.stopImmediatePropagation(); 
         e.preventDefault(); 
        } 
       }); 
      } 
     } 
}); 
})(); 

보기 :

<tr class="" 
    ng-repeat="package in adminManifestVm.Manifest | orderBy:'Id' track by $index" 
    ng-click="adminManifestVm.debinPackage(package.Id);" 
    confirm-click 
    val="Move Package back to Pile?"> 
관련 문제