jQuery find() method not working in AngularJS directive

前端 未结 7 990
说谎
说谎 2021-01-31 14:26

I am having trouble with angularjs directives finding child DOM elements with the injected angular element.

For example I have a directive like so:



        
7条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 15:16

    Before the days of jQuery you would use:

       document.getElementById('findmebyid');
    

    If this one line will save you an entire jQuery library, it might be worth while using it instead.

    For those concerned about performance: Beginning your selector with an ID is always best as it uses native function document.getElementById.

    // Fast:
    $( "#container div.robotarm" );
    
    // Super-fast:
    $( "#container" ).find( "div.robotarm" );
    

    http://learn.jquery.com/performance/optimize-selectors/

    jsPerf http://jsperf.com/jquery-selector-benchmark/32

提交回复
热议问题