Skip to content

Instantly share code, notes, and snippets.

@grapho
Forked from sukima/controllers.application.js
Last active August 16, 2016 16:42
Show Gist options
  • Save grapho/c6e048625bf3cc8905da0bb74b64ddc1 to your computer and use it in GitHub Desktop.
Save grapho/c6e048625bf3cc8905da0bb74b64ddc1 to your computer and use it in GitHub Desktop.
Dependency Injection
import Ember from 'ember';
import Example from '../utils/example';
export default Ember.Controller.extend({
test1: Ember.computed({
get() {
// This is hard to maintain across the app but
// easy for developers to understand.
return Example.create();
}
})
});
import Example from "../utils/example";
export function initialize(application) {
console.log(Example);
application.register("example:main", Example, { instantiate: false });
}
export default {
name: 'example',
initialize
};
export function initialize(instance) {
instance.lookup("example:main");
}
export default {
name: 'example',
initialize
};
import Ember from 'ember';
export default Ember.Service.extend({
foo: 'bar'
});
<h1>Test 1</h1>
<p><code>test1.foo == "{{test1.foo}}"</code></p>
<h1>Test 2</h1>
<p><code>test2.foo == "{{test2.foo}}"</code></p>
{
"version": "0.10.4",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
import Ember from 'ember';
export default Ember.Object.extend({
myService: Ember.inject.service(),
foo: Ember.computed.alias('myService.foo')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment