jsindos jsindos - 11 months ago 62
AngularJS Question

Setting an Angular service on an ES6 class property affects its functionality

I'm using ES6 with Angular following this guide http://angular-tips.com/blog/2015/06/using-angular-1-dot-x-with-es6-and-webpack/. It recommends defining services as classes. In a service definition I'm injecting the

service and attaching it to the class:

export default class Authentication {
constructor($cookieStore) {
this.$cookieStore = $cookieStore;

setAuthenticatedAccount(account) {
this.$cookieStore.put(JSON.stringify(account), 'authenticatedAccount');

is called,
executes but doesn't create the cookie
. The cookie is created if you call
without attaching it to

How can I define services as classes whilst avoiding this problem?

Answer Source

You call the put function the wrong way. Try with this parameter order:

this.$cookieStore.put('authenticatedAccount', JSON.stringify(account));