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

Commit 930ee2d

Browse files
orafaelfragosoRafael Fragoso
authored and
Rafael Fragoso
committed
refactor(jQlite): add the ability to use query selector without jQuery
`angular.element` threw an error if we tried to use query selector directly without jQuery. I thought that this was a silly little fix for the framework. A lot of the projects that I've worked for the past years are only including jQuery to use query selectors on the app (I know that are options for this), and I'm only making this PR because I think it's unnecessary to use `angular.element(document).find()` to accomplish such a small thing and to get the jQlite wrapper with the goodies. Now we can do this, without jQuery: `angular.element('.something')` And get the same result.
1 parent e5c6174 commit 930ee2d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/jqLite.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
* <div class="alert alert-info">**Note:** All element references in AngularJS are always wrapped with jQuery or
4646
* jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.</div>
4747
*
48-
* <div class="alert alert-warning">**Note:** Keep in mind that this function will not find elements
49-
* by tag name / CSS selector. For lookups by tag name, try instead `angular.element(document).find(...)`
50-
* or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`.</div>
48+
* <div class="alert alert-info">**Note:** This function will find elements
49+
* 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(...)`
50+
* or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`, without the wrapper.</div>
5151
*
5252
* ## AngularJS's jqLite
5353
* jqLite provides only the following jQuery methods:
@@ -284,7 +284,7 @@ function JQLite(element) {
284284
}
285285
if (!(this instanceof JQLite)) {
286286
if (argIsString && element.charAt(0) !== '<') {
287-
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
287+
return new JQLite(document.querySelector(element));
288288
}
289289
return new JQLite(element);
290290
}

0 commit comments

Comments
 (0)