2016-10-31 3 views
0

다음과 같은 문제가 있습니다.각도 지시문 및 범위

내보기

<a class="btn btn-hero" confirmation-download-all 
ng-if="downloadPackageLink"><i class="fa fa-download" aria-hidden="true"></i> {{signDocumentDownloadAllButton}}</a> 

에 다음 코드를하고 난 지시어를 가지고

function confirmationDownloadAll(deviceDetector) { 
    return { 
     restrict : 'A', 
     priority : 1, 
     terminal : true, 
     scope : { 
      signDocumentDownloadAllButton : '=', 
     }, 
     link : function (scope, element, attr) { 
      var clickAction = attr.ngClick; 
      element.bind('click', function (event) { 
       event.preventDefault(); 
       if (scope.deviceDetector.os == 'ios') { 
        var sweetOptions = { 
         title : scope.signDocumentDownloadAllNotificationTitleIOS, 
         text : scope.signDocumentDownloadAllNotificationMessageIOS, 
         type : "warning", 
         showCancelButton : false, 
         confirmButtonColor : "#DD6B55", 
         confirmButtonText : scope.signDocumentDownloadAllButton, 
         closeOnConfirm : true 
        }; 
        swal(sweetOptions, 
         function (isConfirm) { 
         if (isConfirm) { 
          var downloadall = document.getElementById('hidden_downloadall'); 
          downloadall.click(); 
          //if (sweetConfirmOption) swal(sweetConfirmOption); 
          //if (attrs.sweetOnConfirm) scope.$evalAsync(attrs.sweetOnConfirm); 
         } 
        }); 
       } else { 
        var downloadall = document.getElementById('hidden_downloadall'); 
        downloadall.click(); 
       } 
      }); 
     } 
    }; 
} 

그리고 내 문제는 내보기에, 버튼의 텍스트를 보여주는 대신, {{signDocumentDownloadAllButton}} 때문이다 $scope. signDocumentDownloadAllButton

나는 매우 단순해야한다고 생각하지만 나는 열망하고 있습니다.

+0

어디에서 'scope.deviceDetector'를 가져 오나요? 당신은'scope' 블록의 일부로 그것을 나열하지 않습니다. – Makoto

+0

jsfiddle [여기] (https://jsfiddle.net/cLe9kxd4/16/)에 코드를 두었고 많은 오류가있었습니다. deviceDetectotr은 서비스가 아닙니다. scope.deviceDetector와 왜 관련이 있는지 이해하지 못했습니다. 나는 그것을 제거했지만 작동하지 않았다. 콘솔에 오류가 있습니까? –

답변

-1

여기에 간다 .......이 주석은 수정해야 할 부분을 지정하십시오.

function confirmationDownloadAll(deviceDetector) { 
return { 
    restrict : 'A', 
    priority : 1, 
    terminal : true, 
    scope : { 
     signDocumentDownloadAllButton : '=', 
    }, 
    // you missed the below line $scope and not just scope 
    link : function ($scope, element, attr) { 
     var clickAction = attr.ngClick; 
     element.bind('click', function (event) { 
      event.preventDefault(); 
      if ($scope.deviceDetector.os == 'ios') { 
       var sweetOptions = { 
        title : $scope.signDocumentDownloadAllNotificationTitleIOS, 
        text : $scope.signDocumentDownloadAllNotificationMessageIOS, 
        type : "warning", 
        showCancelButton : false, 
        confirmButtonColor : "#DD6B55", 
        confirmButtonText : $scope.signDocumentDownloadAllButton, 
        closeOnConfirm : true 
       }; 
       swal(sweetOptions, 
        function (isConfirm) { 
        if (isConfirm) { 
         var downloadall = document.getElementById('hidden_downloadall'); 
         downloadall.click(); 
         //if (sweetConfirmOption) swal(sweetConfirmOption); 
         //if (attrs.sweetOnConfirm) $scope.$evalAsync(attrs.sweetOnConfirm); 
        } 
       }); 
      } else { 
       var downloadall = document.getElementById('hidden_downloadall'); 
       downloadall.click(); 
      } 
     }); 
    } 
}; 
} 
+0

지시어에서, 서비스를 나타내는'$ scope' 대신에 scope 객체를 표현하기 위해'scope'를 사용하는 것이 일반적입니다. 또한,'deviceDetector'를 주입하는 것이이 시나리오에서 * 아무 것도 * 수행 할 수 없다고 확신합니다. 왜냐하면 이것은 심지어 어디서 오는 것인지도 분명하지 않기 때문입니다. – Makoto