我从api中获取一些数据,但是它们是一些字符串,用于单字符串。我需要单独展示它们。以下是它如何进入控制台:
我想在我的应用程序中显示如下:
这已经在其他类似的移动应用程序中显示。但我想知道如何用离子角进行。
这是我如何显示措辞。
.ts
this.wording = this.res[0].policywording;
.html
<div *ngIf="wording">{{wording}}</div>
并且输出与控制台中的相同,不是按顺序我希望像我附加一样显示它。我认为这可能是通过行李箱,但不知道如何使用它。
你必须分解这些数据。像这样的东西:
TS:
this.displayData = [];
if (this.wording) {
const policies = this.wording.split('|').filter(w => w !== '');
this.displayData = [];
policies.forEach((policy) => {
const splited = policy.split('=');
const displayPolicy = {name: splited[0], value: splited[1]};
this.displayData.push(displayPolicy);
});
}
html的:
<div *ngIf="displayData && displayData.length > 0">
<div *ngFor="let policy of displayData">{{policy.name:}} {{policy.value}}</div>
</div>
<div *ngIf="!displayData || displayData.length === 0">No Data available</div>