2013-10-07 5 views
0

jQuery가 Angular에 포함되면 지시문 내부에서 DOM 조작에 $ (요소)와 $ (모두)를 자유롭게 사용할 수 있습니다.요소 대 AngularJS 지시문

그들 사이의 차이점은 무엇입니까? 하나는 다른 것보다 권장됩니까? 그들은 상호 교환이 가능합니까?

답변

3

$(this)$(element)가 항상에 부착 된 지시자를 참조되며, 실행되는 방법의 상황에 의존 할 것이다.

여기에 인위적인 예를 들어 자바 스크립트에서이 키워드에 대한 자세한 내용을 알고 답을 Intersting

module.directive('myDirective', [function() { 
    return { 
     template: '<div><button id="btn">Click Me</button></div>', 
     restrict: 'E', 
     link: function(scope, element, attrs, controller) { 
       $("#btn").on('click', function() { 
        // $(this) != $(element) 
        // $(this) is the button element from the template 
        // $(element) is the directive element 
       }); 
      } 
     } 
}]); 
+0

아름다운! 감사 –

1

각도 js는 선택기에 대한 후드에서 jqlite (최소 jquery 버전)를 사용하기 때문에 각도가 다른 j에서 다른 이름으로도 동일 할 수 있습니다.

는 참조 : AngularJS DOM selector

+0

입니다 : http://stackoverflow.com/questions/3127429/javascript-this-keyword – webcoder