Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Ionic 3在页面模板内加载资产文件_Javascript_Angular_Ionic Framework_Ionic3 - Fatal编程技术网

Javascript 使用Ionic 3在页面模板内加载资产文件

Javascript 使用Ionic 3在页面模板内加载资产文件,javascript,angular,ionic-framework,ionic3,Javascript,Angular,Ionic Framework,Ionic3,我有一个页面,ContentPage,显示我的应用程序静态文件的内容。我的页面的html文件如下(content.html): 当ContentPage打开时,我需要获取一个txt文件,例如1.txt,并将其内容加载到content.html页面中 这是我的页面代码: import {Component} from "@angular/core"; import {IonicPage} from "ionic-angular"; @IonicPage() @Component({ sele

我有一个页面,
ContentPage
,显示我的应用程序静态文件的内容。我的页面的html文件如下(
content.html
):

ContentPage
打开时,我需要获取一个txt文件,例如
1.txt
,并将其内容加载到
content.html
页面中

这是我的页面代码:

import {Component} from "@angular/core";
import {IonicPage} from "ionic-angular";

@IonicPage()
@Component({
  selector: 'page-content',
  templateUrl: 'content.html',
})
export class ContentPage {

  lessonNumber: number;
  pageNumber: number;

  txtContent: string = '';

  constructor() {
    //FIXME - get txt contents
    //txtContent = ...
  }

}
我该怎么做


是否有一个类或插件允许我获取这些文件?

您可以使用
HTTP
请求从txt文件获取数据。您可以在构造函数或服务中编写

constructor() {
    this.http.request('./txt/1.txt')
                     .map(res => res.text()    })
          .subscribe(text => {
            this.txtContent= text;
          });
 }

您可以使用
HTTP
request从txt文件获取数据。您可以在构造函数或服务中编写

constructor() {
    this.http.request('./txt/1.txt')
                     .map(res => res.text()    })
          .subscribe(text => {
            this.txtContent= text;
          });
 }

这里面有一些打字错误。挂起的
}
的匹配
{
在哪里?这里有一些打字错误。挂起的
}
的匹配
{
在哪里?
constructor() {
    this.http.request('./txt/1.txt')
                     .map(res => res.text()    })
          .subscribe(text => {
            this.txtContent= text;
          });
 }