I am a new angular developer but I don't know where I mistake. I find a lot of sources but ı did not adapt my codes. My codes do not work or make get from web client Could you help me with this issue?
My example JSON Data :
{ "id": "123aCaA-9852", "name": "A bank", "address": "adres", "contactName": "Example name", "contactSurname": "Exmple", "contactPhone": "12312312312", "status": false, "city": { "id": 40, "name": "Turkey", "code": 34 }, My Example ts:
export class Kafein {
name:string;
address:string;
}
My example kafein.component.ts
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Kafein } from './kafein';
import { Observable } from 'rxjs/internal/Observable';
@Component({
selector: 'app-kafein',
templateUrl: './kafein.component.html',
styleUrls: ['./kafein.component.css']
})
export class KafeinComponent implements OnInit {
title = "Kafein";
//kafein:Observable<Kafein[]>;
kafein:Kafein[];
constructor(private http: HttpClient) { }
ngOnInit() {
this.getProducts();
}
getProducts(){
//this.kafein = this.http.get<Kafein[]>('http:example');
this.http.get<Kafein[]>('http:example').subscribe(res=>{this.kafein=res});
}
}
My example component.html
<tr *ngFor='let kafein of Kafein'>
<th scope="row">1</th>
<td>{{kafein.name}}</td>
<td>{{kafein.adress}}</td>
</tr>
this.kafein=res as Kafein[]