Я хотел бы отобразить данные из API остальных в моем угловом компоненте.У меня есть некоторые данные из этого URL-адреса заполнителя: https://jsonplaceholder.typicode.com/posts. Я написал для него услугу следующим образом:
Service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpEventType, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http';
import { Observable, of } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class nowService {
serviceApiUrl: string = 'https://jsonplaceholder.typicode.com/posts';
constructor(
private http: HttpClient,
) { }
public title: string;
public id: number;
public body: string;
public userId: number;
public getAll() {
return this.http.get(this.serviceApiUrl);
}
}
Файл component.ts
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpEventType, HttpHeaders, HttpRequest, HttpResponse } from '@angular/common/http';
// Services
import { nowService } from '../../services/now.service';
@Component({
selector: 'app-service-incident',
templateUrl: './service.component.html',
styleUrls: ['./service.component.scss']
})
export class ServiceIncidentComponent implements OnInit {
constructor(private service: nowService) {
}
ngOnInit() {
this.service.getAll().subscribe((data) => {
console.log('Result - ', data);
console.log('data is received');
})
}
}
Я хочу иметь возможность отображать эти данные в таблице.