Get DOM element by scope $id

前端 未结 4 1895
死守一世寂寞
死守一世寂寞 2020-12-08 02:37

I understand I can get the scope by element:

scope = angular.element($0).scope();
scope.$id; // \"003\"

How do I get reverse: Find the DOM

4条回答
  •  盖世英雄少女心
    2020-12-08 03:13

    You can always get the scope using element's id.

    Example:

    html:

    js:

      var myEl = angular.element(document.querySelector('#myId'));
      var myScope = angular.element(myEl).scope(); 
    

    Live example : http://jsfiddle.net/choroshin/7XQA7/2/

    also as David Chase suggested, you can always use batarang - Extends Chrome Developer Tools, adding tools for debugging and profiling AngularJS applications.

提交回复
热议问题