如果用户已登录,则角度更改HTML [英] Angular changing HTML if a user is logged in
问题描述
因此,我尝试在JQuery上使用angular,这有点让人费解.
So I am trying to use angular over JQuery which is a bit of a mind bender.
在我的应用中,我想根据用户登录状态更改文本.如果他已登录,我想显示:我的帐户,如果没有人登录,我想显示:登录/注册.
In my app I want to change text according to a users logged in state. If he is logged in, I want to show: My Account, and if no one is logged in I want to show: Login / Register.
在Jquery中易于实现,不太确定NG的最佳方法.
Easy to do in Jquery, not quite sure the best method for NG.
HTML
<li>
<a (click)="openLoginForm()">
<i class="fa fa-lock"></i> Login / Register</a>
<i class="fa fa-lock"></i> My Account</a>
</li>
我想做的是检查一个变量:loginIn,如果为true,则显示我的帐户";如果为false,则显示登录/注册".
What I would like to do is check a variable: loggedIn, if true it shows "My Account", if false it shows "Login / Register".
我不是100%清楚如何通过Angular2做到这一点...
I am not 100% clear how to do this via Angular2...
推荐答案
类似的事情,当用户登录组件时设置isLogged:
Something like this, set isLogged when user logs on your component:
<a (click)="openLoginForm()">
<i class="fa fa-lock"></i> {{ isLogged ? "My Account" : "Login / Register" }}
</a>
这仅用作简单绑定,它不会检测到更改,因此您可以执行以下操作:
This is only working as simple binding, it will not detect change so you could do somthing like this:
<a (click)="openLoginForm()">
<i class="fa fa-lock"></i> {{ isLoggedTittle }}
</a>
并在组件中设置标题:
isLoggedTittle = logged ? "My Account" : "Login / Register";
这篇关于如果用户已登录,则角度更改HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!