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.
如果它是带有banner
属性的对象,那么您需要在TS代码中使用该use属性
this.craCoreService.banner().subscribe(value => this.banner = value.banner);
使用json
管道在模板中显示对象。
<div class="alert alert-warning" *ngSwitchCase="false"> {{banner | json}}</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.