简体   繁体   English

读取阵列中的API以获取离子,以在文档视图中打开pdf

[英]Read API in an array for ionic to open a pdf in document view

I am new to angular and ionic. 我是棱角和离子的新手。 I have the following API data 我有以下API数据

[{"ID":"1","Title":"Maritime Safety","File_Name":"9c714531945ee24345f60e2105776e23.pdf","Created":"2018-11-07 17:36:55","Modified":"2018-11-07 17:36:55"}]

Which I would like to read through API in my ionic app. 我想在我的离子应用程序中阅读API。 My ionic app code as follows: 我的离子应用程序代码如下:

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { RestProvider } from '../../providers/rest/rest';


@Component({
 templateUrl: 'modal-content.html',
})
export class NavigationDetailsPage {
item;

 constructor(params: NavParams) {
 this.item = params.data.item;
 }
}

@Component({
templateUrl: 'contact.html',
})
export class ContactPage {
 items = [];
 pono: string;
 inventorys: string[];
 errorMessage: string;

 constructor(public nav: NavController, public rest: RestProvider, public 
 navParams: NavParams) {
  this.pono = navParams.get('data');
    this.items = [
    {
      'title': 'Angular',
       'description': 'A powerful Javascript framework for building single 
       page apps. Angular is open source, and maintained by Google.',
      }
    ]
  }

  ionViewDidLoad() {
   this.getInsights();
  }

  getInsights() {
  this.rest.getInsights()
     .subscribe(
       inventorys => this.inventorys = inventorys,
       error =>  this.errorMessage = <any>error);
  }

  openNavDetailsPage(item) {
   this.nav.push(NavigationDetailsPage, { item: item });
 }

}

I am trying to add my API data in an array so instead of title angular will be my title and description will have my pdf name. 我正在尝试将我的API数据添加到数组中,因此我的标题将代替我的标题,而描述将具有我的pdf名称。 Actually, I am trying to use document view where the title is clicked and straight away it opens a pdf where there is a back button on the top to see all the titles. 实际上,我尝试使用单击标题的文档视图,并立即打开一个pdf文件,顶部有一个后退按钮以查看所有标题。

Please advise. 请指教。

service: 服务:

Hardcoded the service section, please replace once your API returns valid response. 对服务部分进行硬编码,一旦您的API返回有效响应,请替换。

getInSights(){
 return of([{"ID":"1","Title":"Maritime Safety","File_Name":"9c714531945ee24345f60e2105776e23.pdf","Created":"2018-11-07 17:36:55","Modified":"2018-11-07 17:36:55"}]);
}

Component: 零件:

getInsights() {
  this.rest.getInsights()
     .subscribe(
       data => {
          this.inventorys = data.map(item=> {
            return {
              title: item.Title,
              description: item. File_Name
           ]);
       },
       error =>  this.errorMessage = <any>error);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM