Files
gilze-angular/app/pages/plane/plane.component.ts
T
2026-06-17 16:11:25 +02:00

69 lines
1.7 KiB
TypeScript

import { Component, OnInit, OnDestroy } from '@angular/core';
import { DataService } from './../../services/data.service';
import { IntervalObservable } from 'rxjs/observable/IntervalObservable';
import { Subscription } from 'rxjs/Subscription';
import { Plane } from "./../../classes/plane.class";
import { Params, ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-plane',
templateUrl: './plane.component.html',
styleUrls: ['./plane.component.css']
})
export class PlaneComponent implements OnInit, OnDestroy {
loading:boolean = true;
error:boolean = false;
name:string = "Loading";
id:number = 0;
public plane:Plane = new Plane(0, "Loading", "Loading", "Loading", "Loading");
public subscription:Subscription;
constructor(private route: ActivatedRoute, private data:DataService){}
getPlane(id:number): void {
this.data.load().then(()=> {
this.data
.plane(id)
.subscribe(b => {
var status = b.status_code;
if(status != 200 && b.data.length != 1)
{
this.loading = false;
this.error = true;
}
else{
this.plane = Plane.toPlane(b.data[0]);
this.name = this.plane.name;
this.loading = false;
}
});
});
}
ngOnInit(): void {
this.id = this.route.snapshot.params['id'];
this.getPlane(this.id);
this.subscription = IntervalObservable.create(5000).subscribe(() => {
console.log("Reloading data...");
this.getPlane(this.id);
});
}
ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}