2016-08-05 4 views
0

사용자의 권한에 따라 사용하지 않도록 설정해야하는 링크가 있습니다. 해당 파일에 대한 JS 지시어주어진 조건에서 href를 비활성화하는 방법은 무엇입니까?

<div ng-repeat="userAgreement in journalist.userAgreements"> 
    <div class="row" ng-repeat="attachment in userAgreement.attachments"> 
     <div class="col-sm-12" style="color: #2a98d4"> 
      <ul style="margin-bottom: 0px; padding-left: 1.5em;"> 
       <li class="fa fa-check-circle" style="font-size: 1.1em; margin: 3px;"> 
        <a target="_blank" href="{{attachment.url}}" ng-click="agreementPermission($event)" class="cursor-pointer" style="font-family: FranklinITCProLight">{{getAttachmentName(userAgreement.agreement, attachment)}}</a> 
       </li> 
      </ul> 
     </div> 
    </div> 
</div> 
<div ng-show="!hasAttachments"> 
    <div class="col-sm-12" style="color: #2a98d4"> 
     <ln code="journalist.completed.documents.empty" args=""></ln> 
    </div> 
</div> 
</div> 

합니다 (ng-click가 작동하지 않습니다) 여기

됩니다 :

define(["app"], function (app) { 
    return app.directive('completedAgreements',[ 
     function() { 
      return { 
       restrict: 'E', 
       templateUrl: '/directives/completed-agreements.html', 
       link: function ($scope, elm, attrs) { 
        $scope.hasAttachments = false; 
        $scope.getAttachmentName = function(agreement, attachment) { 
         $scope.hasAttachments = true; 
         if(attachment.templateId) { 
          return attachment.name; 
         } else { 
          if(agreement.type == 'DIRECT_DEPOSIT') { 
           return "Payment Documents" 
          } else { 
           var specialization = agreement.specialisation.toLowerCase(); 
           return specialization.charAt(0).toUpperCase() + specialization.slice(1) + " Agreement"; 
          } 
         } 
        } 
       } 
      }; 
     } 
    ]) 
}); 

함수 내에 는 아래 링크에 대한 htmn입니다 클릭 수 :

$scope.agreementPermission = function(e) { 
      if (!SecurityService.canViewAgreements()) { 
       showError($uibModal, "You do not have permission to access this attachment. Please contact an administrator.", null, null, null, null, "Access Denied"); 
       e.preventDefault(); 
      } 
     }; 

저는이 자바 스크립트에 익숙하지 않기 때문에이 기능 n이 올바른 위치에 있습니다. html에 대한 js 지시문에 있어야하는 다른 컨트롤러 파일입니까? 따라서 기본적으로 권한이없는 사용자가 링크를 클릭하면 showError 상자가 트리거되고 권한이 있으면 페이지가 링크로 리디렉션됩니다. 어떤 제안이라도 대단히 감사하겠습니다! 나는 더 많은 정보를 제공해야하는지 알려주세요! :-)

+0

Angular의 특성을 잘 모릅니다. 그러나 내가 시도 할 첫 번째 일은 일어날 일의 각 단계에 로깅을 추가하는 것입니다. 그래서, "link"와 "agreementPermission"과 e.preventDefault()를하는 if 문 내에서. 이렇게하면 작동하지 않는 부분이나 작동하지 않는 부분을 파악하는 데 도움이됩니다. – Whothehellisthat

+0

href 값은 각기 다른 응용 프로그램 외부의 다른 페이지로 사용자를 가져 가나요, 아니면 응용 프로그램 내의 단순한 경로입니까? 여기서 몇 가지 아이디어를 생각해 볼 수 있습니다. –

+0

그것의 계약 문서, 메신저 그것의 응용 프로그램 내에서 가정. – keslami

답변

0

는 그것뿐만 아니라 객체로 자바 스크립트를 편집해야 http://www.w3schools.com/tags/ref_attributes.asp

를 참조 <a disabled>에 태그를 <a> 태그를 다시

. ;

object = document.getElementById("MyElem"); 
object.disabled = true; 

또는

object.active = false; 
0
onclick="onClickFunc(event, {{ element.id or class }})" 

function onClickFunc(event, somedata) { 
    event.preventDefault(); // Stops the default behavior 
    // ... 
} 

//에서는 event.preventDefault() : 같은 뭔가 보기 링크의 기본 동작을 중지합니다.

+3

이 코드가 OP에 도움이되는 이유에 대한 설명을 추가하십시오. 이렇게하면 미래의 시청자가 배울 수있는 답을 제공하는 데 도움이됩니다. 자세한 내용은 [답변]을 참조하십시오. –

+0

예, event.preventDefault(); 코드에 추가 된 링크의 기본 동작을 중지합니다. –

3

a.disable{ 
 
    pointer-events: none; 
 
}
<!--You can add css class to disable the link (anchor), example: --> 
 
<a ng-class="{'disable': isAvailable(product.id)}">see product</a>
대신 링크의

0

사용 버튼을 클릭합니다. CSS class = "btn btn-link"(부트 스트랩). 클릭시 functionPermission 함수를 호출하십시오.

+0

어, 그리고 a11y? – gcampbell

+0

@gcampbell – Amit

+0

접근성을 얻지 못했습니다. 스크린 리더와 같은 것들은 버튼과 링크를 다르게 처리합니다. – gcampbell

관련 문제