angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

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

Open orafaelfragoso opened this issue 8 years ago • 6 comments

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...) refactor

What is the current behavior? (You can also link to an open issue here) angular.element('.my-selector') throws an error if jQuery is not included.

What is the new behavior (if this is a feature change)? angular.element('.my-selector') now finds the element and wraps it in a jQlite (or jQuery) object.

Does this PR introduce a breaking change? No

Please check if the PR fulfills these requirements

  • [x] The commit message follows our guidelines: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#commit-message-format
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been added / updated (for bug fixes / features)

Other information:

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.

orafaelfragoso avatar May 14 '17 18:05 orafaelfragoso

There was extensive discussion about making .find(selector) work and we decided against it as it was impossible to defer to querySelectorAll in a simple way that will agree with jQuery (& common sense) due to a design bug of querySelectorAll with respect to running from non-document elements.

But these arguments don't extend to root-level selectors so I can see angular.element(selector) working in JQLite... I just want to make it clear we're not going to support .find(selector).

Thanks for the PR!

mgol avatar May 15 '17 09:05 mgol

@rafaelfragosom Please make sure grunt test passes for you locally, there are some errors.

mgol avatar May 15 '17 09:05 mgol

@mgol I agree, .find(selector) is too ugly for such a small DOM query.

I only want to be on the same page here. Are these changes wellcome or should I close this issue? Is querySelector an option or should I use a different approach? I can see the compatibility at almost 100% on caniuse.

Let me know so I can put some more effort on this.

Thank you.

orafaelfragoso avatar May 15 '17 13:05 orafaelfragoso

@rafaelfragosom I consulted the team and we're OK with making angular.element(selector) work without jQuery but .find(selector) should still fail. As long as those conditions are met, we will accept a PR.

We'll need unit tests that confirm both of those conditions are met. Would you be willing to work on that?

mgol avatar Jul 26 '17 14:07 mgol

@rafaelfragosom Hey, are you still interested in finishing this PR?

mgol avatar Mar 27 '18 20:03 mgol

We're now in LTS mode so no new features are accepted. Changing the milestone.

mgol avatar Jan 26 '19 20:01 mgol