I am new to Angular. I saw similar questions here but still cant get the point. In my service i have:
banner(): Observable<String> {
return this.http.get<String>(`${SERVER_API_URL}/api/banner`);
}
In component:
ngOnInit() {
this.principal.identity().then(account => {
this.account = account;
});
this.registerAuthenticationSuccess();
this.craCoreService.banner().subscribe(value => this.banner = value);
}
And html:
<div class="alert alert-warning" *ngSwitchCase="false">
{{banner}}
</div>
My service method returns simple JSON object with single String property called "banner". But in UI i always get [Object object]. I do not understand how to get value from it. Appreciate any help, thank you.
If it's an object with the banner property, then you need to use that use property in your TS code
this.craCoreService.banner().subscribe(value => this.banner = value.banner);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With