[英]Observable in Angular returns [ Object object ]
I am new to Angular. 我是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: 和html:
<div class="alert alert-warning" *ngSwitchCase="false">
{{banner}}
</div>
My service method returns simple JSON object with single String property called "banner". 我的服务方法返回具有单个String属性(称为“横幅”)的简单JSON对象。 But in UI i always get [Object object].
但是在UI中,我总是得到[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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.