Skip to content

Commit ed6d221

Browse files
author
Your Name
committed
Angular Universal In Depth
1 parent 6d8c494 commit ed6d221

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/app/app.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
</button>
3434
</mat-toolbar>
3535

36+
<div class="spinner-container" *appShellRender>
37+
38+
<mat-spinner></mat-spinner>
39+
40+
</div>
41+
3642

3743
<router-outlet></router-outlet>
3844

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { CourseDialogComponent } from './course-dialog/course-dialog.component';
2929
import {ReactiveFormsModule} from "@angular/forms";
3030
import { HttpClientModule} from '@angular/common/http';
3131
import {AboutComponent} from './about/about.component';
32+
import {AppShellRenderDirective} from "./directives/app-shell-render.directive";
3233

3334

3435

@@ -41,7 +42,8 @@ import {AboutComponent} from './about/about.component';
4142
CourseComponent,
4243
CoursesCardListComponent,
4344
CourseDialogComponent,
44-
AboutComponent
45+
AboutComponent,
46+
AppShellRenderDirective
4547
],
4648
imports: [
4749
BrowserModule.withServerTransition({ appId: 'serverApp' }),
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {
2+
Directive, Inject, OnInit, PLATFORM_ID,
3+
TemplateRef, ViewContainerRef
4+
} from "@angular/core";
5+
import {isPlatformServer} from "@angular/common";
6+
7+
@Directive({
8+
selector: "[appShellRender]"
9+
})
10+
export class AppShellRenderDirective implements OnInit {
11+
12+
constructor(@Inject(PLATFORM_ID) private platformId,
13+
private templateRef: TemplateRef<any>,
14+
private viewContainer: ViewContainerRef) {
15+
16+
}
17+
18+
ngOnInit() {
19+
if (isPlatformServer(this.platformId)) {
20+
this.viewContainer.createEmbeddedView(this.templateRef);
21+
}
22+
else {
23+
this.viewContainer.clear();
24+
}
25+
26+
}
27+
28+
}

0 commit comments

Comments
 (0)