I have common header components and footer components. A list of countries is uploaded to the home page. whenever you click on a country. the page will load and display the text Loading... and then display the header and footer. but I want to show the header and footer by default, without waiting for the page to load completely. My code is here.
application-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() { } }