Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

refactor(jQlite): Add the ability to use query selector without jQuery #15986

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
* <div class="alert alert-info">**Note:** All element references in AngularJS are always wrapped with jQuery or
* jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.</div>
*
* <div class="alert alert-warning">**Note:** Keep in mind that this function will not find elements
* by tag name / CSS selector. For lookups by tag name, try instead `angular.element(document).find(...)`
* or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`.</div>
* <div class="alert alert-info">**Note:** This function will find elements
* by tag name / CSS selector and wrap it in a jQlite object, or in a jQuery object if it's available. You can also query the DOM like `angular.element(document).find(...)`
* or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`, without the wrapper.</div>
*
* ## AngularJS's jqLite
* jqLite provides only the following jQuery methods:
Expand Down Expand Up @@ -284,7 +284,7 @@ function JQLite(element) {
}
if (!(this instanceof JQLite)) {
if (argIsString && element.charAt(0) !== '<') {
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
return new JQLite(window.document.querySelector(element));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good place to add this logic as it'd mean new angular.element(selector) wouldn't work. This whole if should just be removed and the logic should me moved down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, note it should use querySelectorAll, not querySelector as we want to select all matching elements, not one.

}
return new JQLite(element);
}
Expand Down