После вызова службы API у меня в шаблоне есть неопределенная переменная, но я вижу ожидаемый результат в консоли.
Есть мой VideoComponent, который называется API
export class VideoComponent implements OnInit {
video: Video = new Video();
constructor(private apiService: ApiService, private route: ActivatedRoute) {
}
ngOnInit() {
this.route.params.subscribe(params => {
this.apiService.getOneVideoByID(params['id']).subscribe((video: Video) => {
this.video = video;
console.log(this.video);
});
});
}
}
Существует мой сервис API:
export class ApiService {
PHP_API_SERVER = 'http://127.0.0.1/TutoWorld/backend/api';
private headers;
constructor(private httpClient: HttpClient) {
this.headers = new HttpHeaders().set('Content-Type', 'application/json')
}
getOneVideoByID(id: number): Observable<Video> {
return this.httpClient.get<Video>(`${this.PHP_API_SERVER}/readOne?id=${id}`,{headers: this.headers});
}
}
Мой шаблон:
<div class="block5"></div>
<div id="videoContainer">
<p>video title: {{video.titre}} </p>
</div>
И моя модель видео:
export class Video {
id: number;
url: string;
titre: string;
langue: string;
description: string;
date_creation: string;
date_ajout: string;
auteur_id: number;
auteur_nom: string;
}
Если кто-то может помочь мне решить эту проблему вопрос, было бы здорово.
Спасибо