# Using Ember Services in Discourse plugins

**URL:** <https://meta.discourse.org/t/using-ember-services-in-discourse-plugins/51713>\
**Category:** Development\
**Created:** [October 18, 2016, 9:42pm UTC](https://meta.discourse.org/t/using-ember-services-in-discourse-plugins/51713 "2016-10-18T21:42:47Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [October 18, 2016, 9:42pm UTC](https://meta.discourse.org/t/using-ember-services-in-discourse-plugins/51713/1 "2016-10-18T21:42:47Z")

</div>

I am attempting to make use of Ember “[Services](https://guides.emberjs.com/v1.13.0/understanding-ember/dependency-injection-and-service-lookup/)” in a discourse plugin. Right now I am just trying to get a simple proof of concept working based off of [this tutorial](http://www.programwitherik.com/ember-services-tutorial/) online. Unfortunately I can’t get it working and am not sure if it’s something to do with how plugins are loaded in discourse, or if I’m just doing something wrong. Any help would be appreciated!

Right now the plugin is purely clientside, so the plugin.rb just has basic info.

```plaintext
# name: Test Plugin
# about: A plugin to test Ember services in Discourse
# version: 0.0.1
# authors: David Taylor

```

```plaintext
// plugins/myplugin/assets/javascripts/discourse/components/comp-test.js.es6
import Ember from 'ember';  
var inject = Ember.inject;

export default Ember.Component.extend({  
    start: inject.service(),
    message: 'test',
    actions: {
        pressMe: function() {
            var testText = this.get('start').thisistest();
            this.set('message',testText);
            console.log(this.get('start').isAuthenticated);
        }
    }
});

```

```plaintext
// plugins/myplugin/assets/javascripts/discourse/services/start.js.es6
import Ember from 'ember';

export default Ember.Service.extend({  
    isAuthenticated: true,
    thisistest: function() {
        return "hello world";
    }
});

```

```plaintext
<!-- plugins/myplugin/assets/javascripts/discourse/templates/components/comp-test.hbs -->
<button {{action "pressMe"}}>push me</button><br>  
{{message}}

```

```plaintext
<!-- plugins/myplugin/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/testfile.hbs -->
<span>Hello World widget here: {{comp-test}}</span>

```

When the button is clicked, I get an error in the javascript console:  
`Uncaught TypeError: Cannot read property 'thisistest' of undefined`  
which I believe just means that the Service hasn’t been loaded/injected properly. I’m unsure of how to go about debugging this further.

---

_[View the full topic](https://meta.discourse.org/t/using-ember-services-in-discourse-plugins/51713)._
