After fetching data from Django server I want to display it in Angular, I used :
<p>
{{todo.id}}
</p>
and without any errors, I do not see the data in my template, the above code wants to display the value of id in a JSON.
service:
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) {
}
private URL="http://127.0.0.1:8000/api/product/"
getApi(arg:any){
console.log(arg);
return this.http.get (this.URL)
.subscribe(data=> {
console.log('we got',data)
})
console.log(arg);
}
}
component:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'angpr';
todo:any;
constructor(public api: ApiService) {
}
ngOnInit(): void{
this.todo=this.api.getApi('hey');
}
}
Why can't I see the data in template and what should I do to display it in the template?