【发布时间】:2018-12-11 02:45:24
【问题描述】:
我一直在到处寻找这个答案。我有一个标题组件,我想显示当前登录用户的名称。 在 header.component.html:
<a href="javascript:void(0)" class="nav-link" ngbDropdownToggle>
<i class="fa fa-user"></i>USERNAME HERE<b class="caret"></b>
</a>
在 header.component.ts 中,我在构造函数和 ngOnInit 之外有这个方法
displayName(){
return localStorage.getItem("username");
}
有没有办法在我想要的标题上显示该用户名?
【问题讨论】:
-
在您的 html {{displayName()}} 中,请参阅 angular.io/guide/displaying-data
-
@Eliseo {{displayName()}} 没用跨度>
-
在函数 displayName 中放 console.log("*",localStorage.getItem("username")) 看看函数返回的值是多少
-
哦,我明白了,它返回 null 所以 displayName 可能有效,只需要找到用户名。
-
在本地存储中,用户拥有所有信息、ID、用户名和电子邮件。我怎样才能让它只显示用户名?