Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit 918b356

Browse files
author
Your Name
committed
RxJs and Reactive Patterns Angular Architecture Course ongoing
1 parent cefcbe9 commit 918b356

8 files changed

+91
-2
lines changed

images/loading.gif

43.6 KB
Loading

src/app/app.component.html

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
<messages></messages>
55

6+
<loading></loading>
7+
68
<div>
79

810
<router-outlet></router-outlet>

src/app/app.module.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import {SafeUrlPipe} from "./shared/pipes/safe-url.pipe";
2929
import {LessonsPagerService} from "./services/lessons-pager.service";
3030
import { MessagesComponent } from './messages/messages.component';
3131
import {MessagesService} from "./services/messages.service";
32+
import { LoadingComponent } from './loading/loading.component';
33+
import {LoadingService} from "./loading/loading.service";
3234

3335

3436
@NgModule({
@@ -49,7 +51,8 @@ import {MessagesService} from "./services/messages.service";
4951
CourseComponent,
5052
LessonDetailComponent,
5153
SafeUrlPipe,
52-
MessagesComponent
54+
MessagesComponent,
55+
LoadingComponent
5356
],
5457
imports: [
5558
BrowserModule,
@@ -63,7 +66,8 @@ import {MessagesService} from "./services/messages.service";
6366
NewsletterService,
6467
UserService,
6568
CoursesHttpService,
66-
MessagesService
69+
MessagesService,
70+
LoadingService
6771

6872
],
6973
bootstrap: [AppComponent]

src/app/loading/loading.component.css

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
.loading-indicator {
4+
width: 100%;
5+
position: absolute;
6+
text-align: center;
7+
}
8+
9+
.loading-indicator img {
10+
width: 75px;
11+
margin-top: 100px;
12+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="loading-indicator" *ngIf="loading$ | async">
2+
<img src="/images/loading.gif">
3+
</div>
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { LoadingComponent } from './loading.component';
4+
5+
describe('LoadingComponent', () => {
6+
let component: LoadingComponent;
7+
let fixture: ComponentFixture<LoadingComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ LoadingComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(LoadingComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});

src/app/loading/loading.component.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import {LoadingService} from "./loading.service";
3+
import {Observable} from "rxjs";
4+
5+
@Component({
6+
selector: 'loading',
7+
templateUrl: './loading.component.html',
8+
styleUrls: ['./loading.component.css']
9+
})
10+
export class LoadingComponent implements OnInit {
11+
12+
loading$: Observable<boolean>;
13+
14+
constructor(private loadingService: LoadingService) {
15+
16+
}
17+
18+
ngOnInit() {
19+
this.loading$ = this.loadingService.loading$;
20+
}
21+
22+
}

src/app/loading/loading.service.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Injectable} from '@angular/core';
2+
import {BehaviorSubject} from "rxjs";
3+
4+
5+
@Injectable()
6+
export class LoadingService {
7+
8+
private subject = new BehaviorSubject<boolean>(false);
9+
10+
loading$ = this.subject.asObservable();
11+
12+
13+
loadingOn() {
14+
this.subject.next(true);
15+
}
16+
17+
loadingOff() {
18+
this.subject.next(false);
19+
}
20+
21+
}

0 commit comments

Comments
 (0)