ember.js - Emberjs Set CurrentUserController from LoginController -
i have currentuser objectcontroller :
app.currentusercontroller = em.objectcontroller.extend({ username: 'test', email : 'test@test.com' })
when user logs in, want set currentuser's username, email etc:
app.logincontroller = ember.controller.extend({ needs: 'currentuser', login: function(){ var self = this; var data = this.getproperties('username', 'password'); self.set('errormessage', null); $.ajax({ type: "post", url: url, mimetype: "text/xml", success: function(response){ app.currentuser.set('username', data.username); app.currentuser.set('email', data.email); self.transitiontoroute('home'); }, error: function(){ self.set('errormessage', true); } }); } });
i've tried above no luck.
there no app.currentuser instance available.
app.currentuser.set('username', data.username);
since using 'needs', can access controller this:
this.get('controllers.currentuser')
make sure 'this' correctly binded in xhr response.
finally, since ember getters/setters supports 'paths', can set properties this:
this.set('controllers.currentuser.email', data.email);
Comments
Post a Comment