Mam wspólne elementy nagłówka i komponenty stopki. lista krajów ładuje się na stronie głównej. po kliknięciu na kraj. strona zostanie przeładowana i wyświetli tekst Loading...
, a następnie wyświetlanie nagłówka i stopki. ale chcę wyświetlić domyślny nagłówek i stopkę bez czekania na załadowanie pełnej strony. Mój kod tutaj.Jak wyświetlić wspólny nagłówek i stopkę domyślnie w kancie 2?
app-routing.module.ts
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', component: HomepageComponent,},
{ path: ':city', component: CountryDetailComponent },
{ path: ':city/:subscategory', component: ExploreListComponent },
{ path: ':city/:subscategory/:singleitem', component: DetailedPageComponent },
];
app.component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
template: `
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
`,
})
export class AppComponent { }
header.component.ts
import { Component,Renderer } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Component({
moduleId: module.id,
selector: 'app-header',
template: `header html script`,
})
export class HeaderComponent {
constructor(title: Title) { }
}
footer.component.ts
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app-footer',
template: `comman footer html script`,
})
export class FooterComponent {
}
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
homepage.component.ts
@Component({
selector: 'my-app',
templateUrl: 'homepage.component.html',
styleUrls: ['homepage.component.css'],
providers: [ CountriesService]
})
export class HomepageComponent {
ngOnInit() {
}
}
To powinno być zachowanie domyślne. Spróbuj rozwiązać ten problem, jeśli użyjesz 'import: [RouterModule.forRoot (myRoutes, {useHash: true})] –
@ GünterZöchbauer, nie działa. – vel
Trudno powiedzieć, ponieważ powinno to po prostu działać. Czy możesz rozmnażać się w Plunker? –