Changeset View
Changeset View
Standalone View
Standalone View
src/app/_shared/arealist/areaList.component.ts
- This file was added.
import { Component, OnInit, OnDestroy, Input } from '@angular/core'; | |||||
import { Subject } from 'rxjs/Subject'; | |||||
import { Area } from '../../_models/area'; | |||||
import { AreaService } from '../../_services/area.service'; | |||||
@Component({ | |||||
templateUrl: 'areaList.component.html', | |||||
styleUrls: ['./areaList.component.scss'], | |||||
selector: 'app-area-list' | |||||
}) | |||||
export class AreaListComponent implements OnInit, OnDestroy { | |||||
@Input() public showAdd = true; | |||||
areas = new Array<Area>(new Area('', '', 0, 0)); | |||||
componentDestroyed: Subject<boolean> = new Subject(); | |||||
loading = true; | |||||
constructor( | |||||
private areaService: AreaService, | |||||
) { } | |||||
ngOnInit() { | |||||
this.areaService.getAreas() | |||||
.takeUntil(this.componentDestroyed) | |||||
.subscribe(areas => { | |||||
this.areas = []; | |||||
for (let i = 0; i < areas.length; i++) { | |||||
this.areaService.getAreaRep(areas[i].name) | |||||
.takeUntil(this.componentDestroyed) | |||||
.subscribe(result => { | |||||
let area; | |||||
area = new Area( | |||||
areas[i].name, | |||||
areas[i].displayname, | |||||
result.reputation, | |||||
result.spread | |||||
); | |||||
this.areas.push(area); | |||||
this.loading = false; | |||||
}); | |||||
} | |||||
}); | |||||
} | |||||
ngOnDestroy() { | |||||
this.componentDestroyed.next(true); | |||||
this.componentDestroyed.complete(); | |||||
} | |||||
} |