Skip to content

Instantly share code, notes, and snippets.

@jgwhite
Last active January 13, 2016 15:04
Show Gist options
  • Save jgwhite/bdfff67c35dc3af149a0 to your computer and use it in GitHub Desktop.
Save jgwhite/bdfff67c35dc3af149a0 to your computer and use it in GitHub Desktop.
Ember-cli Initializer Example
// 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()
});
@adentranter
Copy link

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')

});

@michaelBenin
Copy link

Thanks for this example!

@rchithaluri
Copy link

Executable example , Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment