cloud
This commit is contained in:
@@ -1 +1,22 @@
|
||||
<p>list works!</p>
|
||||
<div *ngIf="isNear">
|
||||
|
||||
</div>
|
||||
|
||||
<div *ngIf="!isNear && location">
|
||||
<h1>
|
||||
{{location.location}}
|
||||
</h1>
|
||||
<div *ngFor="let waypoinst of location.waypoints">
|
||||
<h3>
|
||||
{{waypoinst.name}}
|
||||
</h3>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<h1></h1>
|
||||
|
||||
<h3></h3>
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {Locations} from "../interface/data";
|
||||
import {ReadjsonService} from "../service/readjson.service";
|
||||
import {Observable} from "rxjs";
|
||||
import {ActivatedRoute} from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: 'app-list',
|
||||
@@ -6,8 +10,45 @@ import {Component, OnInit} from '@angular/core';
|
||||
styleUrls: ['./list.component.css']
|
||||
})
|
||||
export class ListComponent implements OnInit {
|
||||
private locationParams: string | undefined
|
||||
locations: Partial<Locations>[] | undefined;
|
||||
location: Partial<Locations> | undefined;
|
||||
|
||||
isNear: boolean = true;
|
||||
|
||||
|
||||
constructor(private route: ActivatedRoute ,private readjsonService: ReadjsonService) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.params.subscribe(params => {
|
||||
this.locationParams = params['location'];
|
||||
});
|
||||
|
||||
this.readjsonService.getLocations().subscribe(locations => {
|
||||
this.locations = locations;
|
||||
this.checkDataPopulated();
|
||||
});
|
||||
|
||||
if (this.locationParams != null) {
|
||||
this.readjsonService.getLocation(this.locationParams).subscribe(location => {
|
||||
this.location = location;
|
||||
this.checkDataPopulated();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private checkDataPopulated(): void {
|
||||
if (this.locations && this.location) {
|
||||
console.log("Dati popolati correttamente:", this.locations, this.location);
|
||||
for (let i = 0; i < this.locations.length; i++) {
|
||||
if (this.locations[i].location === this.locationParams) {
|
||||
this.location = this.locations[i];
|
||||
console.log("Location trovata:", this.location);
|
||||
this.isNear= false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user