【发布时间】:2017-09-20 16:44:10
【问题描述】:
我有常见的页眉组件和页脚组件。国家列表正在主页上加载。每当点击国家。页面将重新加载并显示文本Loading...,然后显示页眉和页脚。但我想在不等待整页加载的情况下显示页眉和页脚默认值。我的代码在这里。
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() {
}
}
【问题讨论】:
-
这应该是默认行为。如果您使用
imports: [RouterModule.forRoot(myRoutes, {useHash: true})],请尝试此问题是否得到解决 -
@GünterZöchbauer,不工作。
-
很难说,因为这应该可以。你能在 Plunker 中复制吗?
-
@GünterZöchbauer,看到这个 plunker plnkr.co/edit/P1jR4cj4m2yiP2NoAHs5?p=preview。没有错误。但页面未加载。
-
它什么也没做。您应该将文件移动到
src文件夹中。只需双击文件名并在它们前面加上src/