I am fetching the api json placeholder and i am trying to get a page matching with the id of the route en the object. By console logging everything seems to work, when i navigate to the specific page, the object with the matching id shows up on my console but when i try to put the data on my html it just won't show up. And i get no errors. I don't know what to do. screenshot of the page
//SERVICE FILE//
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Stream } from './stream';
import { Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class StreamService{
constructor(private http: HttpClient) { }
getStream():Observable<Stream[]>{
return this.http.get<Stream[]>("https://jsonplaceholder.typicode.com/albums/1/photos");
}
getLiveStream(id: number): Observable<Stream> {
const url = `https://jsonplaceholder.typicode.com/albums/1/photos?id=${id}`;
return this.http.get<Stream>(url);
}
}
//TS FILE//
import { Component, OnInit } from '@angular/core';
import { StreamService } from '../stream.service';
import { DomSanitizer } from '@angular/platform-browser';
import {ActivatedRoute} from '@angular/router';
import { Stream } from '../stream';
@Component({
selector: 'app-livestream',
templateUrl: './livestream.component.html',
styleUrls: ['./livestream.component.scss']
})
export class LivestreamComponent implements OnInit {
liveStream!: Stream;
constructor(
private streamService: StreamService,
private sanitizer: DomSanitizer,
private route: ActivatedRoute,
) { }
//is voor de "sanitizing unsafe style value url" error te vermijden//
public getSantizeUrl(url : string) {
return this.sanitizer.bypassSecurityTrustUrl(url);
}
ngOnInit() {
this.getLiveStream();
}
getLiveStream():void{
const id = Number(this.route.snapshot.paramMap.get('id'));
this.streamService.getLiveStream(id).subscribe(liveStream =>{
this.liveStream = liveStream;
console.log(this.liveStream);
})
}
}
//INTERFACE FILE
export interface Stream {
id: number;
title: string;
url: string;
thumbnailUrl: string;
}
// HTML FILE
<div class="container">
<h3>Livestream</h3>
<div>
<h4> {{liveStream?.title}} </h4>
</div>
</div>