Skip to content

Instantly share code, notes, and snippets.

@jelhan
Created March 21, 2019 14:25
Show Gist options
  • Save jelhan/73733849f3fcd5f75aa63f3ee85a27e5 to your computer and use it in GitHub Desktop.
Save jelhan/73733849f3fcd5f75aa63f3ee85a27e5 to your computer and use it in GitHub Desktop.
stackoverflow-55261082
import Controller from '@ember/controller';
import { computed } from '@ember/object';
import { inject as injectService } from '@ember/service';
export default Controller.extend({
currentSession: injectService(),
bar: computed('currentSession.foo', function() {
return this.currentSession.foo;
}),
actions: {
change() {
this.currentSession.set('foo', 'changed');
}
}
});
import Service from '@ember/service';
export default Service.extend({
foo: 'foo bar baz',
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
Property of service: {{currentSession.foo}}
<br>
Alias in controller: {{currentSession.foo}}
<br>
<button onclick={{action "change"}}>mutate property</button>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment