I am trying to make a simple switch when statement in my Angular template and the switch statement output must be "You're a user" but it says that I am a guest.
What is wrong with my code?
<p><strong>Current role</strong></p>
<p>{{ app.currentUser.role }}</p>
<p><strong>Role to compare with</strong></p>
<p>{{ app.userRoles.user }}</p>
output:
Current role
user
Role to compare with
user
Switch statement
<div ng-switch on="app.currentUser.role">
<div ng-switch-when="app.userRoles.admin">You're admin.</div>
<div ng-switch-when="app.userRoles.moderator">You're moderator.</div>
<div ng-switch-when="app.userRoles.user">You're a user.</div>
<div ng-switch-default>You're a guest.</div>
</div>
output:
You're a guest.
Angular controller:
function MainController() {
my = this;
my.currentUser = { role : 'user'};
my.userRoles = { user : 'user' };
}
Plunker link: https://plnkr.co/edit/oCKVTjfTwkwYO9UVQU6X?p=preview