Skip to content

Commit

Permalink
Angular Universal In Depth
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 11, 2020
1 parent ed6d221 commit 373f853
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
</button>
</mat-toolbar>

<div class="spinner-container" *appShellRender>

<mat-spinner></mat-spinner>

</div>
<router-outlet></router-outlet>

<div class="spinner-container" *appShellRender>

<router-outlet></router-outlet>
<mat-spinner></mat-spinner>

</div>

</mat-sidenav-container>
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {ReactiveFormsModule} from "@angular/forms";
import { HttpClientModule} from '@angular/common/http';
import {AboutComponent} from './about/about.component';
import {AppShellRenderDirective} from "./directives/app-shell-render.directive";
import {AppShellNoRenderDirective} from "./directives/app-shell-norender.directive";



Expand All @@ -43,7 +44,8 @@ import {AppShellRenderDirective} from "./directives/app-shell-render.directive";
CoursesCardListComponent,
CourseDialogComponent,
AboutComponent,
AppShellRenderDirective
AppShellRenderDirective,
AppShellNoRenderDirective
],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
Expand Down
3 changes: 2 additions & 1 deletion src/app/course/course.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ <h2>{{course?.description}}</h2>

</div>

<mat-table class="lessons-table mat-elevation-z8" [dataSource]="dataSource">
<mat-table class="lessons-table mat-elevation-z8"
[dataSource]="dataSource" *appShellNoRender>

<ng-container matColumnDef="seqNo">

Expand Down
28 changes: 28 additions & 0 deletions src/app/directives/app-shell-norender.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
Directive, Inject, OnInit, PLATFORM_ID,
TemplateRef, ViewContainerRef
} from "@angular/core";
import {isPlatformServer} from "@angular/common";

@Directive({
selector: "[appShellNoRender]"
})
export class AppShellNoRenderDirective implements OnInit {

constructor(@Inject(PLATFORM_ID) private platformId,
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef) {

}

ngOnInit() {
if (isPlatformServer(this.platformId)) {
this.viewContainer.clear();
}
else {
this.viewContainer.createEmbeddedView(this.templateRef);
}

}

}
2 changes: 1 addition & 1 deletion src/app/home/home.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<div class="courses-panel">
<div class="courses-panel" *appShellNoRender>

<mat-tab-group>

Expand Down

0 comments on commit 373f853

Please sign in to comment.