angular.element vs document.getElementById or jQuery selector with spin (busy) control

后端 未结 10 2436
感动是毒
感动是毒 2020-11-28 02:18

I\'m using the \"Angularised\" version of the Spin control, as documented here: http://blog.xvitcoder.com/adding-a-weel-progress-indicator-to-your-angularjs-application/

10条回答
  •  独厮守ぢ
    2020-11-28 02:24

    It can work like that:

    var myElement = angular.element( document.querySelector( '#some-id' ) );
    

    You wrap the Document.querySelector() native Javascript call into the angular.element() call. So you always get the element in a jqLite or jQuery object, depending whether or not jQuery is available/loaded.

    Official documentation for angular.element:

    If jQuery is available, angular.element is an alias for the jQuery function. If jQuery is not available, angular.element delegates to Angulars built-in subset of jQuery, that called "jQuery lite" or jqLite.

    All element references in Angular are always wrapped with jQuery or jqLite (such as the element argument in a directives compile or link function). They are never raw DOM references.

    In case you do wonder why to use document.querySelector(), please read this answer.

提交回复
热议问题