Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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
Angular ionic2显示加载、警报和日志的最佳实践是什么?_Angular_Typescript_Ionic2 - Fatal编程技术网

Angular ionic2显示加载、警报和日志的最佳实践是什么?

Angular ionic2显示加载、警报和日志的最佳实践是什么?,angular,typescript,ionic2,Angular,Typescript,Ionic2,我正在寻找ionic2显示加载、警报和控制台日志的最佳实践 因此,不要在每页中重复下面的代码,这样我就可以调用它一次 例如,显示加载的代码示例: showLoading() { this.loading = this.loadingCtrl.create({ content: '' }); this.loading.present(); } 创建提供程序并显示上一个提供程序的加载是最佳做法吗?或者提供程序不支持加载或类似操作 谢谢。如果您需要,我通常

我正在寻找ionic2显示加载、警报和控制台日志的最佳实践

因此,不要在每页中重复下面的代码,这样我就可以调用它一次

例如,显示加载的代码示例:

  showLoading() {
    this.loading = this.loadingCtrl.create({
      content: ''
    });
    this.loading.present();
  }
创建提供程序并显示上一个提供程序的加载是最佳做法吗?或者提供程序不支持加载或类似操作


谢谢。

如果您需要,我通常会创建一个lib文件夹或模块。然后,我创建一些提供者。对于警报,您可以创建提供程序:

import { Injectable } from '@angular/core';
import { AlertController } from 'ionic-angular';

@Injectable()
export class Alert {

  constructor(
    public alertCtrl: AlertController
  ) {}

  show(title: string, subTitle: string, buttons: Array<string>): void{
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: subTitle,
      buttons: buttons
    });
    alert.present();
  }
}
然后,您可以在具有模块路径映射的任何组件中重用,例如:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { LoadingController } from 'ionic-angular';

@Injectable()
export class Loader {

  loader: any;

  constructor(
    public http: HttpClient,
    public loadingCtrl: LoadingController
  ) {}

  present(msg = `Please wait...`) {
    this.loader = this.loadingCtrl.create({
      content: "Please wait..."
    });
    this.loader.present();
  }

  dismiss() {
    this.loader.dismiss();
  }
}
import { Alert, Toast } from '@lib';
public getLoading(message?) {
    if (!message) {
      message = 'Loading...';
    }
    return this.loadCtrl.create({content: message});
  }
这是最佳实践吗?是的,我想。您编写的代码更少,并且可以重用lib提供程序


希望我能帮忙

如果需要,我通常会创建一个lib文件夹或模块。然后,我创建一些提供者。对于警报,您可以创建提供程序:

import { Injectable } from '@angular/core';
import { AlertController } from 'ionic-angular';

@Injectable()
export class Alert {

  constructor(
    public alertCtrl: AlertController
  ) {}

  show(title: string, subTitle: string, buttons: Array<string>): void{
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: subTitle,
      buttons: buttons
    });
    alert.present();
  }
}
然后,您可以在具有模块路径映射的任何组件中重用,例如:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { LoadingController } from 'ionic-angular';

@Injectable()
export class Loader {

  loader: any;

  constructor(
    public http: HttpClient,
    public loadingCtrl: LoadingController
  ) {}

  present(msg = `Please wait...`) {
    this.loader = this.loadingCtrl.create({
      content: "Please wait..."
    });
    this.loader.present();
  }

  dismiss() {
    this.loader.dismiss();
  }
}
import { Alert, Toast } from '@lib';
public getLoading(message?) {
    if (!message) {
      message = 'Loading...';
    }
    return this.loadCtrl.create({content: message});
  }
这是最佳实践吗?是的,我想。您编写的代码更少,并且可以重用lib提供程序


希望我能帮忙

我通常创建一个UtilProvider,然后创建一个方法来显示加载对话框,例如:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { LoadingController } from 'ionic-angular';

@Injectable()
export class Loader {

  loader: any;

  constructor(
    public http: HttpClient,
    public loadingCtrl: LoadingController
  ) {}

  present(msg = `Please wait...`) {
    this.loader = this.loadingCtrl.create({
      content: "Please wait..."
    });
    this.loader.present();
  }

  dismiss() {
    this.loader.dismiss();
  }
}
import { Alert, Toast } from '@lib';
public getLoading(message?) {
    if (!message) {
      message = 'Loading...';
    }
    return this.loadCtrl.create({content: message});
  }
您可以添加超时,也可以返回create、call present,然后在之后退出


我认为将其用于AlertController并不是很好,因为您不会处理de按钮单击

我通常创建一个UtilProvider,然后创建一个显示加载对话框的方法,例如:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { LoadingController } from 'ionic-angular';

@Injectable()
export class Loader {

  loader: any;

  constructor(
    public http: HttpClient,
    public loadingCtrl: LoadingController
  ) {}

  present(msg = `Please wait...`) {
    this.loader = this.loadingCtrl.create({
      content: "Please wait..."
    });
    this.loader.present();
  }

  dismiss() {
    this.loader.dismiss();
  }
}
import { Alert, Toast } from '@lib';
public getLoading(message?) {
    if (!message) {
      message = 'Loading...';
    }
    return this.loadCtrl.create({content: message});
  }
您可以添加超时,也可以返回create、call present,然后在之后退出


我认为用它来提醒控制器不是很好,因为你不会处理取消按钮点击

你是一个救生员!你是个救生员!