Skip to content

Commit dbfe9ba

Browse files
IsmaestroIsmael Ramos
authored andcommitted
feat(service workers): added service workers support
1 parent 0ce4a6e commit dbfe9ba

File tree

14 files changed

+157
-10
lines changed

14 files changed

+157
-10
lines changed

.angular-cli.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"tsconfig": "tsconfig.app.json",
2222
"testTsconfig": "tsconfig.spec.json",
2323
"prefix": "app",
24-
"stylesUrls": [
25-
""
26-
],
24+
"serviceWorker": true,
2725
"styles": [
2826
"assets/css/reset.css",
2927
"assets/css/loading.css",
@@ -63,6 +61,7 @@
6361
},
6462
"defaults": {
6563
"styleExt": "css",
66-
"component": {}
64+
"component": {
65+
}
6766
}
6867
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Live DEMO [here](http://angularexampleapp.com/)!
6363
* Lazy loading modules
6464
* Interceptors and Events (Progress bar active, if a request is pending)
6565
* CRUD: create, update and remove heroes
66+
* Service Workers!
6667
* Custom example library
6768
* Search bar, to look for heroes
6869
* Angular Pipes

package-lock.json

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
"license": "MIT",
55
"scripts": {
66
"start": "ng serve --aot",
7+
"http-server": "http-server dist/ -c-1",
78
"build": "ng build --prod",
89
"deploy": "ng build --prod --base-href / && angular-cli-ghpages",
910
"test": "ng test --watch=false --code-coverage",
10-
"e2e": "ng e2e --prod",
11+
"e2e": "ng e2e",
1112
"e2e:home": "ng e2e --serve false --prod --specs=./e2e/home/**/*.e2e-spec.ts",
1213
"e2e:heroeslist": "ng e2e --serve false --prod --specs=./e2e/heroes-list/**/*.e2e-spec.ts",
1314
"lint": "ng lint",
@@ -44,6 +45,7 @@
4445
"@angular/language-service": "^5.2.9",
4546
"@angular/material": "5.1.1",
4647
"@angular/platform-server": "5.2.3",
48+
"@angular/service-worker": "^5.2.9",
4749
"@ngx-translate/core": "9.1.1",
4850
"@ngx-translate/http-loader": "2.0.1",
4951
"@types/jasmine": "2.8.6",
@@ -54,6 +56,7 @@
5456
"codelyzer": "4.1.0",
5557
"coveralls": "3.0.0",
5658
"hammerjs": "2.0.8",
59+
"http-server": "^0.11.1",
5760
"jasmine-core": "2.9.1",
5861
"jasmine-spec-reporter": "4.2.1",
5962
"karma": "2.0.0",

src/app/app.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<div>
22
<app-nav></app-nav>
3-
<router-outlet></router-outlet>
3+
<router-outlet *ngIf="isOnline;else isOffline"></router-outlet>
4+
<ng-template #isOffline>
5+
<div>
6+
<p class="offline-error">{{'offlineMessage' | translate}}&nbsp;&nbsp;&nbsp;<span>:&nbsp;)</span></p>
7+
</div>
8+
</ng-template>
49
</div>
510
<app-footer></app-footer>

src/app/app.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ declare const Modernizr;
1515

1616
export class AppComponent {
1717

18+
isOnline = navigator.onLine;
19+
1820
constructor(private translateService: TranslateService,
1921
private title: Title,
2022
private meta: Meta,

src/app/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ import {ProgressInterceptor} from './shared/interceptors/progress.interceptor';
1919
import {TimingInterceptor} from './shared/interceptors/timing.interceptor';
2020
import {SampleModule} from 'angular-example-library';
2121

22+
import {ServiceWorkerModule} from '@angular/service-worker';
23+
import {environment} from '../environments/environment';
24+
2225
@NgModule({
2326
imports: [
2427
BrowserModule,
28+
ServiceWorkerModule.register('/ngsw-worker.js', {enabled: environment.production}),
2529
BrowserAnimationsModule,
2630
FormsModule,
2731
HttpClientModule,

src/assets/css/styles.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,17 @@ pre {
104104
display: block;
105105
text-align: left;
106106
word-wrap: break-word;
107+
}
108+
109+
.offline-error {
110+
font-size: 1em;
111+
font-weight: 300;
112+
padding: 1rem;
113+
text-align: center;
114+
115+
span {
116+
transform: rotate(90deg);
117+
font-size: 0.8em;
118+
display: inline-flex;
119+
}
107120
}

src/assets/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@
4747
"error404": "404 Error",
4848
"mayTheForce": "May the force be with you",
4949
"updateBrowser": "You are using an old browser, please update it and reload the page.",
50-
"firstTwoHeroesById": "Heroes (1-2)"
50+
"firstTwoHeroesById": "Heroes (1-2)",
51+
"offlineMessage": "Without connection we can not load anything!"
5152
}

src/assets/i18n/es.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@
4747
"error404": "Error 404",
4848
"mayTheForce": "Que la fuerza te acompañe",
4949
"updateBrowser": "Estas usando un navegador antiguo, por favor actualiza la versión y recarga la página.",
50-
"firstTwoHeroesById": "Heroes (1-2)"
50+
"firstTwoHeroesById": "Heroes (1-2)",
51+
"offlineMessage": "Sin conexión no podemos cargar nada!"
5152
}

0 commit comments

Comments
 (0)