# Existing component check in js file

**URL:** <https://discuss.emberjs.com/t/existing-component-check-in-js-file/9624>\
**Category:** Ember Data\
**Created:** [February 1, 2016, 9:08am UTC](https://discuss.emberjs.com/t/existing-component-check-in-js-file/9624 "2016-02-01T09:08:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaurav\_kumar1989](https://avatars.discourse-cdn.com/v4/letter/g/a8b319/32.png) [@gaurav\_kumar1989](https://discuss.emberjs.com/u/gaurav_kumar1989)\
**Post date:** [February 1, 2016, 9:08am UTC](https://discuss.emberjs.com/t/existing-component-check-in-js-file/9624/1 "2016-02-01T09:08:36Z")

</div>

Hi , i need check whether a component is already existing or not in one js file , is there any way how to do this ? whether this is feasible or not ?

---

<div class="post-metadata">

**Author:** ![workmanw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/workmanw/32/14929_2.png) [@workmanw](https://discuss.emberjs.com/u/workmanw)\
**Post date:** [February 1, 2016, 1:48pm UTC](https://discuss.emberjs.com/t/existing-component-check-in-js-file/9624/2 "2016-02-01T13:48:33Z")

</div>

I don’t fully understand what you mean by, _“check whether a component is already existing or not in one js file”_. If you’re referring to just checking to see if a component globally exists or not, you can use the “Owners API”. Here is an example:

```auto
import Ember from 'ember';

export default Ember.Component.extend({
  init() {
    this._super(...arguments);
 
    let owner = Ember.getOwner(this);
    if (!owner.hasRegistration('component:xFoo')) {
      /* do something? */
    }
  }
});

```

The Owner API is newly added in [Ember 2.3](http://emberjs.com/blog/2016/01/15/ember-2-3-released.html#toc_introducing-owners-and-deprecating-containers). If you’re using an older version of ember, you can use this [polyfill](https://github.com/rwjblue/ember-getowner-polyfill). Also relevant docs [ContainerProxyMixin](http://emberjs.com/api/classes/ContainerProxyMixin.html) and [RegistryProxyMixin](http://emberjs.com/api/classes/RegistryProxyMixin.html).

---

<div class="post-metadata">

**Author:** ![gaurav\_kumar1989](https://avatars.discourse-cdn.com/v4/letter/g/a8b319/32.png) [@gaurav\_kumar1989](https://discuss.emberjs.com/u/gaurav_kumar1989)\
**Post date:** [February 1, 2016, 2:21pm UTC](https://discuss.emberjs.com/t/existing-component-check-in-js-file/9624/3 "2016-02-01T14:21:22Z")

</div>

thanks for replying workmanw 🙂

very true i wanted to check already created component globally , but i m using ember 1.11 , i m afraid this API wont work . i tried using following code

```
					if(this.container.lookup('template:templateName));

```

it is working fine . If component is not there , it will return as undefined .

---

<div class="post-metadata">

**Author:** ![workmanw](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/workmanw/32/14929_2.png) [@workmanw](https://discuss.emberjs.com/u/workmanw)\
**Post date:** [February 1, 2016, 2:42pm UTC](https://discuss.emberjs.com/t/existing-component-check-in-js-file/9624/4 "2016-02-01T14:42:27Z")

</div>

A couple of notes.

1. The [polyfill](https://github.com/rwjblue/ember-getowner-polyfill) that I linked will work with Ember 1.11. You should really consider using this because it will be one less thing to fix if you’re upgrading to Ember 2.x.

2. If you’re going to use the container, you shouldn’t use `lookup` to test it because in some cases it will create a new instance of for that lookup. Instead use `has`, `this.container.has('template:templateName');`.
