我有一个简单的Angular.io应用程序.(angular-cli/4.1.0)
我有一个NavbarComponent,用于呈现用户名.
第一次访问应用程序时我没有登录,我的应用程序重定向到LoginComponent.我的NavBar也被渲染但没有用户名.成功登录后,我被重定向到我的HomeComponent.
这就是问题所在.我的NavBar不显示用户名.但是,如果我执行刷新/ ctrl + r,则会呈现用户名.
怎么了?
app.component.html
<nav-bar></nav-bar>
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)
navbar.compoment.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'nav-bar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
me;
ngOnInit() {
this.me = JSON.parse(localStorage.getItem('currentUser'));
}
}
Run Code Online (Sandbox Code Playgroud)
login.component.ts
import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AlertService, AuthenticationService } from '../_services/index';
@Component({
moduleId: module.id,
templateUrl: 'login.component.html'
})
export class LoginComponent implements OnInit {
model: any = {};
loading …Run Code Online (Sandbox Code Playgroud) 似乎无法向<ngb-tabset>标记添加自定义CSS类。
使用<ngb-tabset>它时,将生成以下html:
<ul role="tablist" class="nav nav-tabs justify-content-start">
我需要将类添加到中<ul>。我怎么做?
我希望我<ul>看起来像这样:
<ul class="nav nav-tabs custom-tabs move-left">