Skip to content

Commit f6262bd

Browse files
committed
AMP/task7/features: load-spinner like service in service
1 parent 28ae08b commit f6262bd

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

angular-starter/src/app/angular-intro/angular-intro.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {
22
Component,
33
OnInit,
44
ChangeDetectionStrategy,
5+
Inject,
56
} from '@angular/core';
7+
import { LoaderBlockServices } from './core';
68

79
@Component({
810
selector: 'intro',
@@ -12,6 +14,9 @@ import {
1214
})
1315

1416
export class IntroComponent implements OnInit {
17+
constructor(
18+
@Inject('load-spinner') private _loaderBlockServices: LoaderBlockServices,
19+
) {}
1520
public ngOnInit() {
1621
console.log('hello `INTRO` component');
1722
}

angular-starter/src/app/angular-intro/angular-intro.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
LoaderBlockServices,
2121
SearchService,
2222
AuthorizationService,
23-
AuthorizedHttpService,
23+
// AuthorizedHttpService,
2424
} from './core/services';
2525

2626
// function toArray(obj) {
@@ -65,12 +65,13 @@ export class IntroModule {
6565
providers: [
6666
// --------------------------------------------------------------------
6767
// AuthorizedHttpService,
68-
{provide: 'ext-http', useClass: AuthorizedHttpService},
68+
// {provide: 'ext-http', useClass: AuthorizedHttpService},
6969
AuthorizationService,
7070

7171
ModalWindowServices,
72-
LoaderBlockServices,
7372

73+
// {provide: LoaderBlockServices, useClass: LoaderBlockServices},
74+
{provide: 'load-spinner', useClass: LoaderBlockServices},
7475
CourseServices,
7576

7677
SearchService,

angular-starter/src/app/angular-intro/core/services/course.services.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, Inject } from '@angular/core';
22
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
33
import { Observable } from 'rxjs/Observable';
44
import 'rxjs/add/operator/map';
@@ -24,15 +24,15 @@ import {
2424
RequestMethod
2525
} from '@angular/http';
2626

27-
// import { LoaderBlockServices } from '../services';
27+
import { LoaderBlockServices } from '../services';
2828

2929
@Injectable()
3030
export class CourseServices {
3131
private sourceList: BehaviorSubject<Course[]>;
3232
private baseUrl = BASE_URL;
3333
private end = 0;
3434
constructor(
35-
// private _loaderBlockServices: LoaderBlockServices,
35+
@Inject('load-spinner') private _loaderBlockServices: LoaderBlockServices,
3636
private _http: Http,
3737
) {
3838
console.log('### CourseService constructor ###');
@@ -72,7 +72,7 @@ export class CourseServices {
7272
}
7373

7474
public removeItem(id: number): void {
75-
// this._loaderBlockServices.Show();
75+
this._loaderBlockServices.Show();
7676

7777
// const currentID = this.sourceList.value.findIndex((item) => item.id === id);
7878
// if (currentID >= 0) {
@@ -120,7 +120,7 @@ export class CourseServices {
120120
}
121121
)
122122
;
123-
// settimeout(() =>this._loaderBlockServices.Hide(), 1000);
123+
setTimeout(() => this._loaderBlockServices.Hide(), 1000);
124124
}
125125

126126
public loadMoreItem(count: number): void {

angular-starter/src/app/angular-intro/courses/courses.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88

99
import {
1010
CourseServices,
11-
LoaderBlockServices,
11+
// LoaderBlockServices,
1212
SearchService,
1313
} from '../core/services';
1414
import { FilterPipe } from '../core/pipes';
@@ -30,7 +30,7 @@ export class CoursesComponent implements OnInit, OnDestroy {
3030
private listeners: Subscription[] = [];
3131

3232
constructor(
33-
private _loaderBlockServices: LoaderBlockServices,
33+
// private _loaderBlockServices: LoaderBlockServices,
3434
private _courseServices: CourseServices,
3535
private _filter: FilterPipe<Course>,
3636
private _searchService: SearchService,
@@ -72,10 +72,10 @@ export class CoursesComponent implements OnInit, OnDestroy {
7272
console.log(`courses.handler emit.type=${emit.type}`);
7373
switch (emit.type) {
7474
case 'deletter': {
75-
this._loaderBlockServices.Show();
75+
// this._loaderBlockServices.Show();
7676
this._courseServices.removeItem(emit.value);
7777
// ...no service in service?
78-
setTimeout( () => this._loaderBlockServices.Hide(), 1500);
78+
// setTimeout( () => this._loaderBlockServices.Hide(), 1500);
7979
break;
8080
}
8181
}

angular-starter/src/app/angular-intro/loaderBlock/loaderBlock.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
OnDestroy,
55
ChangeDetectionStrategy,
66
ChangeDetectorRef,
7+
Inject,
78
} from '@angular/core';
89

910
import { LoaderBlockServices } from '../core/services';
@@ -21,7 +22,7 @@ export class LoaderBlockComponent implements OnInit, OnDestroy {
2122
private listener: Subscription;
2223

2324
constructor(
24-
private _loaderBlockServices: LoaderBlockServices,
25+
@Inject('load-spinner') private _loaderBlockServices: LoaderBlockServices,
2526
private _changeDetectorRef: ChangeDetectorRef,
2627
) {}
2728

0 commit comments

Comments
 (0)