首先,抱歉,如果我的英语不完美,我就是法国人 .

我正在创建一个带有Ionic 3 / angular 4的移动应用程序 .

我的数据存储在“assets / data”中的本地JSON文件中,我正在使用Provider访问它 . 我有一个带有公式的homePage,我的'选择器/选项输入'的数据值,我请求我的提供者通过过滤/排序等返回数据...

一切都有效,但......有点难看 . 现在,我实际上是在我的表单顶部使用一个按钮来初始化我的Provider,因为我在我的Provider构造函数中调用了'http.get'方法(是的......我知道它有点不好) .

我正在使用这个临时解决方案,等待在启动屏幕或'ionViewDidLoad'事件中找到初始化我的提供程序的方法...

我的Provider构造函数:

@Injectable()
export class DataBaseProvider {
  capaciteUrl = './assets/data/capacite.json';
  mixageUrl = "./assets/data/mixage.json";
  mixageData: any;
  capaciteData: any;

constructor(public http: Http) {
    console.log('dataBase init');
    this.http.get(this.capaciteUrl)
      .map(res => res.json())
      .subscribe( data => this.capaciteData = data.data);
    this.http.get(this.mixageUrl)
      .map(res => res.json())
      .subscribe( data => this.mixageData = data.data);
  }

我的homePage.ts中的'初始化程序'功能(按钮调用)

init() {
    this.dataBase.getDataSelector()
      .then(data => {
        this.mixage = data['mixage'];
        this.capacite = data['capacite'];
        this.firstIngredient = this.secondIngredient = data['ingredient'];
      })
  }

我的表格的一部分:

<ion-select [(ngModel)]="mixageSelector" okText="Select">
<ion-option *ngFor="let mix of mixage" [value]="mix.id"> {{mix.name}} </ion-option>
</ion-select>

我在哪里可以调用Http.get方法或如何在我的应用程序的加载/ splashScreen中重写我的模块来调用Http方法? (我也尝试在ionViewDidLoadEvent()中调用我的getDataSelector(),但没有任何改变...)