Last active
January 13, 2016 15:04
-
-
Save jgwhite/bdfff67c35dc3af149a0 to your computer and use it in GitHub Desktop.
Ember-cli Initializer Example
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
// app/initializers/csrf.js | |
export default { | |
name: 'csrf', | |
initialize: function(container, app) { | |
app.inject('route', 'csrf', 'service:csrf'); | |
app.inject('controller', 'csrf', 'service:csrf'); | |
} | |
} | |
// app/services/csrf.js | |
export default Ember.Object.extend({ | |
token: function() { | |
// logic to fetch csrf token here | |
}.property() | |
}); |
Thanks for this example!
Executable example , Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
using the above code. if you wanted to use the service within a controller
would you reference in with this.csrf.token?
Example:
export default = Ember.Controller.extend({
token: function() {
return this.csrf.token();
}.property('this.csrf.token')
});