Last active
March 21, 2019 06:54
-
-
Save rinoldsimon/c4c29c7a758e97e74480801009bd3247 to your computer and use it in GitHub Desktop.
changing service property and accessing it globally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
name1: null, | |
name2: null, | |
init() { | |
this._super(...arguments); | |
// print initial value | |
this.set('name1', (this.get('serviceName').name)); // hello | |
// change value of name property in service | |
this.get('serviceName').changeName("hai"); | |
// print changed value | |
this.set('name2', (this.get('serviceName').name)); // hai | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function initialize(application) { | |
application.inject('controller', 'serviceName', 'service:service-name'); | |
// if needed | |
application.inject('route', 'serviceName', 'service:service-name'); | |
application.inject('component', 'serviceName', 'service:service-name'); | |
} | |
export default { | |
initialize | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
name: "hello", | |
changeName(name) { | |
this.set('name', name); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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