Guest User

Untitled

a guest
Dec 12th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. [
  2. "{'id': 1, 'building': 'Edificio 4', 'zone': 'Sin zonas', 'floor': 1, 'school': 1}",
  3. "{'id': 2, 'building': 'Edificio 15', 'zone': 'Sin zonas', 'floor': 0, 'school': 1}",
  4. "{'id': 3, 'building': 'Edificio 15', 'zone': 'Sin zonas', 'floor': 1, 'school': 1}",
  5. "{'id': 4, 'building': 'Edificio 2', 'zone': 'C', 'floor': 2, 'school': 2}",
  6. "{'id': 5, 'building': 'Edificio 2', 'zone': 'B', 'floor': 3, 'school': 2}",
  7. "{'id': 6, 'building': 'Edificio 7', 'zone': 'J', 'floor': 7, 'school': 2}"
  8. ]
  9.  
  10. import { Component, OnInit, ViewEncapsulation } from '@angular/core';
  11. import { Observable } from 'rxjs/Rx';
  12. import { Injectable } from '@angular/core';
  13. import { HttpClient } from '@angular/common/http';
  14.  
  15. //this is the data class
  16. class Place{
  17. constructor(public id: string, public building: string, public zone: string, public floor: string, public school: string) { }
  18. }
  19.  
  20. @Component({
  21. selector: 'app-locker',
  22. template: `
  23. //here i have a template
  24. `,
  25. styleUrls: ['./locker.component.css'],
  26.  
  27. })
  28.  
  29. @Injectable()
  30. export class LockerComponent implements OnInit {
  31.  
  32. places: Place[];
  33. //if I manually add the data by hand here it works,
  34. //I want to fetch the JSON data to this array
  35.  
  36. campus: String;
  37. building: String;
  38. floor: String;
  39. zone: String;
  40. type: String;
  41.  
  42. buildings = [];
  43. floors = [];
  44. zones = [];
  45. types = [];
  46.  
  47. constructor(private http: HttpClient) {}
  48. ngOnInit(): void {
  49. this.http.get('./assets/test.json').subscribe(data => {
  50. this.places = data;
  51. });
  52. }
  53. }
Add Comment
Please, Sign In to add comment