1

링크 기능의 이름이 지정되지 않은 경우 어떻게 지시어를 제거 할 수 있습니까? 더 구체적으로는 select-ui 지시어를 꾸미고 싶습니다.이름없는 링크 기능을 사용하는 데코 레이팅 지시문

.directive('uiSelect', function() { 
    return { 
      restrict: 'EA', 
      scope: true, 
      compile: function(tElement, tAttrs) { 
       //some code 
       return function(scope, element, attrs, ctrls){ 
         //some code here 
         //how do I extend this? 
       } 
      } 
    } 

}); 

이 내가 시도하는 방법이지만, 나에게 오류 Cannot read property 'apply' of undefined을주고, 링크 기능이 지시어에 이름이되지 않기 때문에 : 이것은 그들의 지시가 정의하는 방법이다

.decorator('uiSelectDirective', function($delegate, Restangular){ 
    var directive; 
    directive = $delegate[0]; 
    console.log(directive, $delegate); 
    directive.scope = { 
     endpoint: '=', 
     items: '=', 
     parameters: '=' 
    }; 
    directive.compile = function() { 
     return function($scope, element, attrs){ 
      directive.link.apply(this, arguments); 
      // custom code here 
     } 
    }; 
    return $delegate; 
}); 

편집

나는 제안 된 접근 방식을 시도했지만 문제가 발생했습니다.

.decorator('uiSelectDirective', function($delegate, Restangular){ 
    var directive; 
    directive = $delegate[0]; 
    directive.scope = { 
     endpoint: '=', 
     items: '=', 
     parameters: '=' 
    }; 


    directive.compile = function(originalCompile) { 
     var args = arguments; 
     return function($scope, element, attrs){ 
      console.log($scope); // this here is returning element instead of scope? 
      return originalCompile.apply(this, args); 

     } 
    }(directive.compile); 


    return $delegate; 
}); 

대신 $scope 내가 요소 변수 ([div.ui-select-container.ui-select-bootstrap.dropdown])를 받고 있어요

. 나는 또한 tAttrs가 정의되지 않았다는 에러를 가지고 있는데, 이것은 메인 compule 함수의 매개 변수이다. 내가 컴파일 기능을 확장하기 위해이 같은이 무언가를

답변

1

... 어떻게 든 함수에 인수를 전달되지 적용 같은데요 : 내가 몇 가지 문제로 실행 해요

directive.compile = function(originalCompile) { 
    return function() { 
    var oldLink = originalCompile.apply(this, arguments); 

    return function($scope, element, attrs) { 
     // custom code for link here 
     return oldLink.apply(this, arguments) 
    } 
    } 
}(directive.compile); 
+0

를 업데이트 된 질문을 참조하시기 바랍니다 :) –

+0

죄송하지만, 죄송합니다. 업데이트 된 코드를 확인하십시오. – dfsq