0
在我的應用程序組件html中,我有一個選擇器和路由器插座。當我嘗試通過單擊鏈接進行導航時,選擇器仍然存在。我如何隱藏選擇器?只應顯示路由器插座。Angular 2路由隱藏選擇器導航
app.component.html
<nav>
<a [routerLink]="['/heroes']">Click here</a>
</nav>
<router-outlet></router-outlet> <-- Display the content here
<feed></feed> <--- feed component selector
app.component.ts
import { Component, OnInit } from '@angular/core';
import 'rxjs/add/operator/map';
@Component({
selector: "app",
templateUrl: "app/app.component.html"
})
export class AppComponent implements OnInit {
ngOnInit() {
}}
app.routing.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HeroComponent } from "./components/hero/hero.component";
const routes: Routes = [
{ path: 'heroes', component: HeroComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routingComponents = [HeroComponent];
的index.html
<app>Loading...</app>
這怎麼辦?
謝謝!它現在有效。 –
不客氣:) – Karim
我也可以像這樣使用* ngIf =「router.url.includes('/')」,只有在主頁面或根頁面時,它才應該呈現feed組件.. –