我是Angular的新手.我在这里看到了类似的问题,但仍然无法说明问题.在我的服务中,我有:
banner(): Observable<String> {
return this.http.get<String>(`${SERVER_API_URL}/api/banner`);
}
Run Code Online (Sandbox Code Playgroud)
在组件中:
ngOnInit() {
this.principal.identity().then(account => {
this.account = account;
});
this.registerAuthenticationSuccess();
this.craCoreService.banner().subscribe(value => this.banner = value);
}
Run Code Online (Sandbox Code Playgroud)
和HTML:
<div class="alert alert-warning" *ngSwitchCase="false">
{{banner}}
</div>
Run Code Online (Sandbox Code Playgroud)
我的服务方法返回简单的JSON对象,该对象具有名为"banner"的单个String属性.但在UI中我总是得到[Object object].我不明白如何从中获取价值.感谢任何帮助,谢谢.
如果它是banner属性的对象,那么您需要在TS代码中使用该use属性
this.craCoreService.banner().subscribe(value => this.banner = value.banner);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
471 次 |
| 最近记录: |