以下代码出现的地方为angular框架下的ts,HTML代码 在前端页面上并不能展示出dv-indicator组件下绑定的数据 <dv-indicator *ngIf="ECSSalable === 0 || !ECSSalable" id="ECSSingleRate" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;"> <dv-indicator *ngIf="ECSSalable === 1" id="ECSSingleRateGreen" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;"> <dv-indicator *ngIf="ECSSalable === 2" id="ECSSingleRateYellow" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;"> <dv-indicator *ngIf="ECSSalable === 3" id="ECSSingleRateRed" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;"> 其中, id="ECSSingleRate"属性在ts文件中的配置如下 "field": "dataInfo.IOC_COCKPIT_ASSETS_PC_RESOURCE_METRIC.ecs_spec_salable_rate", 请问我要怎样修改代码,使得可以取到后端API接口中的数据并呈现到前端页面
时间: 2023-12-05 09:22:43 浏览: 53
首先,你需要在对应的组件的 TypeScript 文件中定义 `ECSSalable` 属性,然后在该组件的 `ngOnInit` 方法中调用后端 API 接口获取数据。获取到数据后,将其赋值给 `ECSSalable` 属性即可。
在 HTML 文件中,你可以使用 Angular 的插值表达式 `{{}}` 来展示从后端 API 获取到的数据。示例如下:
```
<dv-indicator *ngIf="ECSSalable === 0 || !ECSSalable" id="ECSSingleRate" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;">{{ ECSSalable }}</dv-indicator>
<dv-indicator *ngIf="ECSSalable === 1" id="ECSSingleRateGreen" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;">{{ ECSSalable }}</dv-indicator>
<dv-indicator *ngIf="ECSSalable === 2" id="ECSSingleRateYellow" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;">{{ ECSSalable }}</dv-indicator>
<dv-indicator *ngIf="ECSSalable === 3" id="ECSSingleRateRed" style="padding: 0px 0px 2px 0; height: 36px; line-height: 36px; font-weight: 400;">{{ ECSSalable }}</dv-indicator>
```
在这个示例中,`{{ ECSSalable }}` 将会显示从后端 API 获取到的 `ECSSalable` 数据。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)