Skip to content

angular.element() can not be called with a selector, because angular:angular does not depend and load jQuery like angularjs:angular did  #314

@smoke

Description

@smoke

angular.element() uses jQuery if it is loaded prior angular itself, if jQuery is not loaded first it uses jqLite.
angularjs:angular did depend on jQuery and loaded it first, but with angular:angular this is not the case.

Change to angular:angular was introduced since v0.8.5 and this commit 8b0acbe.

So the issues is that angular.element() on its turn does not support arbitrary selectors and code like var backgroundColor = angular.element('body').css('background-color') would fail with:

Uncaught Error: [jqLite:nosel] Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element
http://errors.angularjs.org/1.3.15/jqLite/nosel

A quick workaround would be to change angular.element('body').css('background-color') to angular.element(document).find('body').css('background-color') - this effectively uses the .find() method of a wrapped element, however this could be a problem for huge libraries.

As much as I like jQuery I would recommend not depending on it, since you have angular in place.

So the only problem here is - how to provide choice to people stuck with jQuery? In other words - how to effectively load jQuery prior angular, if this is required?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions