Reputation: 14835
I see that on lot of Ember-cli projects jQuery is called with Ember.$()
instead of $()
.
Is there a specific reason?
Upvotes: 3
Views: 1177
Reputation: 822
Generally, it's best to use this.$ within your controller, view, or component so that way the element selection stays within the scope of the component.
But if you must access jQuery not bound to a particular element, Ember.$ is the safer way, especially if you're dealing with some of the global jQuery queues, like pending ajax requests. Using Ember.$ you're using the jQuery that's included with ember and not some other instance of JQuery.
Upvotes: 3
Reputation: 2693
Usually Ember
has been imported already, and by using Ember.$
you avoid referencing a global dependency. It's not actually that great an idea, and you can actually import jQuery directly.
// you can name the import `$` is you do desire
import jQuery from 'jquery';
jQuery()
Do note, there is a difference between Ember.$()
and this.$()
. The this
version within components is the equivalent of jQuery(this.element)
.
Upvotes: 13