【发布时间】:2020-10-30 20:20:54
【问题描述】:
这是我获取角度数据的代码, 我试图让它对用户更友好,加载需要一段时间,我正在寻找一种方法来添加 angular 加载器我是 angular 新手。
我正在使用 ionic cli 通过 json 数据构建移动应用程序提要
import { Component, OnInit } from '@angular/core';
import { DataService } from "../data.service";
@Component({
selector: 'app-articlespage',
templateUrl: './articlespage.page.html',
styleUrls: ['./articlespage.page.scss'],
})
export class ArticlespagePage implements OnInit {
//id : any[];
title : any[];
author : any[];
date : any[];
content : any[];
constructor(private dataService: DataService) { }
ngOnInit() {
this.dataService.getRemoteData().subscribe(data => {
console.log("Remote Data:" + JSON.stringify(data));
//console.log(data);
this.parseJson(data);
});
}
parseJson(data)
{
let jsonArray = data;
//this.id = [];
this.title = [];
this.author = [];
this.date = [];
this.content = [];
for(let i=0; i< jsonArray.length ; i++)
{
let jsonObject = jsonArray[i];
//this.id.push(jsonObject.id);
this.title.push(jsonObject.title);
this.author.push(jsonObject.author.name);
this.date.push(jsonObject.created_at );
this.content.push(jsonObject.blog_entry );
}
}
}
html:
<ion-content fullscreen>
<h2 > Articles </h2>
<ion-card class="feedspotcard-1 box" *ngFor=" let item of title; let i = index;">
<ion-card-content>
<div class="box-shadow">
<div class="coolbar"></div>
<!-- <p> <span> Id : </span> <span innerHTML={{id[i]}}> </span> </p> -->
<h4> <span innerHTML={{title[i]}}> </span> </h4>
<p> <span innerHTML={{content[i]}}> </span> </p>
<p> <span> author : </span> <span innerHTML={{author[i]}}> </span> </p>
<p> <span> date : </span> <span innerHTML={{date[i]}}> </span> </p>
</div>
</ion-card-content>
</ion-card>
</ion-content>
不是必须的,但结果:
【问题讨论】:
标签: json angular spinner loader