aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.module.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/app.module.ts')
-rw-r--r--client/src/app/app.module.ts130
1 files changed, 130 insertions, 0 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts
new file mode 100644
index 000000000..950b3c48e
--- /dev/null
+++ b/client/src/app/app.module.ts
@@ -0,0 +1,130 @@
1import { NgModule, ApplicationRef } from '@angular/core';
2import { BrowserModule } from '@angular/platform-browser';
3import { FormsModule, ReactiveFormsModule } from '@angular/forms';
4import { HttpModule, RequestOptions, XHRBackend } from '@angular/http';
5import { RouterModule } from '@angular/router';
6import { removeNgStyles, createNewHosts } from '@angularclass/hmr';
7
8import { FileSelectDirective } from 'ng2-file-upload/ng2-file-upload';
9import { ProgressbarModule } from 'ng2-bootstrap/components/progressbar';
10import { PaginationModule } from 'ng2-bootstrap/components/pagination';
11import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
12
13/*
14 * Platform and Environment providers/directives/pipes
15 */
16import { ENV_PROVIDERS } from './environment';
17import { routes } from './app.routes';
18// App is our top level component
19import { AppComponent } from './app.component';
20import { AppState } from './app.service';
21import { AccountComponent, AccountService } from './account';
22import { LoginComponent } from './login';
23import {
24 LoaderComponent,
25 VideosComponent,
26 VideoAddComponent,
27 VideoListComponent,
28 VideoMiniatureComponent,
29 VideoSortComponent,
30 VideoWatchComponent,
31 VideoService
32} from './videos';
33import {
34 FriendsComponent,
35 FriendAddComponent,
36 FriendListComponent,
37 FriendService,
38 UsersComponent,
39 UserAddComponent,
40 UserListComponent,
41 UserService,
42 AdminComponent,
43 MenuAdminComponent
44} from './admin';
45import { MenuComponent } from './menu.component';
46import { AuthService, AuthHttp, RestExtractor, RestService, SearchComponent, SearchService } from './shared';
47
48// Application wide providers
49const APP_PROVIDERS = [
50 AppState,
51
52 {
53 provide: AuthHttp,
54 useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) => {
55 return new AuthHttp(backend, defaultOptions, authService);
56 },
57 deps: [ XHRBackend, RequestOptions, AuthService ]
58 },
59
60 AuthService,
61 RestExtractor,
62 RestExtractor, RestService, VideoService, SearchService, FriendService, UserService, AccountService
63];
64/**
65 * `AppModule` is the main entry point into Angular2's bootstraping process
66 */
67@NgModule({
68 bootstrap: [ AppComponent ],
69 declarations: [
70 AppComponent,
71 BytesPipe,
72 FileSelectDirective,
73 AccountComponent,
74 LoginComponent,
75 LoaderComponent,
76 VideosComponent,
77 VideoAddComponent,
78 VideoListComponent,
79 VideoSortComponent,
80 VideoMiniatureComponent,
81 VideoWatchComponent,
82 FriendsComponent,
83 FriendAddComponent,
84 FriendListComponent,
85 UsersComponent,
86 UserAddComponent,
87 UserListComponent,
88 AdminComponent,
89 MenuAdminComponent,
90 MenuComponent,
91 SearchComponent
92 ],
93 imports: [ // import Angular's modules
94 BrowserModule,
95 FormsModule,
96 ReactiveFormsModule,
97 HttpModule,
98 RouterModule.forRoot(routes),
99 ProgressbarModule,
100 PaginationModule
101 ],
102 providers: [ // expose our Services and Providers into Angular's dependency injection
103 ENV_PROVIDERS,
104 APP_PROVIDERS
105 ]
106})
107export class AppModule {
108 constructor(public appRef: ApplicationRef, public appState: AppState) {}
109 hmrOnInit(store) {
110 if (!store || !store.state) return;
111 console.log('HMR store', store);
112 this.appState._state = store.state;
113 this.appRef.tick();
114 delete store.state;
115 }
116 hmrOnDestroy(store) {
117 const cmpLocation = this.appRef.components.map(cmp => cmp.location.nativeElement);
118 // recreate elements
119 const state = this.appState._state;
120 store.state = state;
121 store.disposeOldHosts = createNewHosts(cmpLocation);
122 // remove styles
123 removeNgStyles();
124 }
125 hmrAfterDestroy(store) {
126 // display new elements
127 store.disposeOldHosts();
128 delete store.disposeOldHosts;
129 }
130}