Reputation: 4825
I am creating a simple ember app which gets data from laravel 4 restful api and uses its authentication feature. What i want to create is when user logs in, the menu item that points to login page in ember needs to be refreshed without reloading the page and changes into logout link pointing to logout controller. I am using simple flag concept in application controller to check the true or false value to display corresponding menu, but the flaw in that concept is that it needed to be refrshed.
How can i make, when user logs in, in ember app the login menu changes automatically to logout menu.
here is the code i have done so far
Application controller:
App.ApplicationController = Ember.Controller.extend({
login_check: localStorage.checklogin
});
Handlebars Application Template
{{#if login_check}}
<li>{{#linkTo "logout" }}Logout{{/linkTo}}</li>
{{else}}
<li>{{#linkTo "login" }}Login{{/linkTo}}</li>
{{/if}}
Upvotes: 1
Views: 241
Reputation: 2520
You need to make login_check a computed property, so ember reevaluate it and inform observers. Suposed that localStorage is an App property...
App.ApplicationController = Ember.Controller.extend({
login_checkBinding: 'App.localStorage.checklogin'
});
Upvotes: 1