1
|
import { NgModule, ApplicationRef } from '@angular/core';
|
2
|
import { BrowserModule } from '@angular/platform-browser';
|
3
|
import { HttpModule } from '@angular/http';
|
4
|
import { FormsModule } from '@angular/forms';
|
5
|
|
6
|
import { AppComponent } from './app.component';
|
7
|
import { HomeComponent } from './home/home.component';
|
8
|
import { AboutComponent } from './about/about.component';
|
9
|
import { ApiService } from './shared';
|
10
|
import { routing } from './app.routing';
|
11
|
|
12
|
import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
|
13
|
|
14
|
@NgModule({
|
15
|
imports: [
|
16
|
BrowserModule,
|
17
|
HttpModule,
|
18
|
FormsModule,
|
19
|
routing
|
20
|
],
|
21
|
declarations: [
|
22
|
AppComponent,
|
23
|
HomeComponent,
|
24
|
AboutComponent
|
25
|
],
|
26
|
providers: [
|
27
|
ApiService
|
28
|
],
|
29
|
bootstrap: [AppComponent]
|
30
|
})
|
31
|
export class AppModule {
|
32
|
constructor(public appRef: ApplicationRef) {}
|
33
|
hmrOnInit(store) {
|
34
|
console.log('HMR store', store);
|
35
|
}
|
36
|
hmrOnDestroy(store) {
|
37
|
let cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
|
38
|
// recreate elements
|
39
|
store.disposeOldHosts = createNewHosts(cmpLocation);
|
40
|
// remove styles
|
41
|
removeNgStyles();
|
42
|
}
|
43
|
hmrAfterDestroy(store) {
|
44
|
// display new elements
|
45
|
store.disposeOldHosts();
|
46
|
delete store.disposeOldHosts;
|
47
|
}
|
48
|
}
|