小编Chr*_*rks的帖子

Angular.io/Angular 4.如何在触发另一个组件视图时刷新它

我有一个简单的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)

angular2-routing angular

5
推荐指数
1
解决办法
2万
查看次数

ng-bootstrap,如何为ngb-tabset添加一个类?

似乎无法向<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">

ng-bootstrap angular

5
推荐指数
0
解决办法
814
查看次数

标签 统计

angular ×2

angular2-routing ×1

ng-bootstrap ×1