1
resposta

Problema na execução do NavLifecycles

Arquivo home.ts:

import { Component } from "@angular/core";
import { NavController, LoadingController, AlertController } from "ionic-angular";
import { Carro } from "../../modelos/carro";
import { HttpErrorResponse } from "@angular/common/http";
import { CarrosServiceProvider } from "../../providers/carros-service/carros-service";


@Component({
  selector: "page-home",
  templateUrl: "home.html"
})
export class HomePage {
  public carros: Carro[];

  constructor(
    public navCtrl: NavController,
    private _loadingCtrl: LoadingController,
    private _alertCtrl: AlertController,
    private _carrosService: CarrosServiceProvider
  ) {}

  ionViewDidLoad() {
    let loading = this._loadingCtrl.create({
      content: "Aguarde carros..."
    });

    loading.present();

    this._carrosService.lista().subscribe(
      carros => {
        this.carros = carros;
        loading.dismiss();
      },
      (err: HttpErrorResponse) => {
        console.log(err);
        loading.dismiss();
        this._alertCtrl
          .create({
            title: "Falha na conexão",
            subTitle:
              "Não foi possível carregar a lista de carros. Tente novamente mais tarde",
            buttons: [{ text: "Ok" }]
          })
          .present();
      }
    );
  }
}

Arquivo do NavLifecycles:

export interface NavLifecycles {
  ionViewDidLoad?(): void;
}

Código de erro

Error: Uncaught (in promise): Error: No provider for CarrosServiceProvider!
Error: No provider for CarrosServiceProvider!
    at injectionError (http://localhost:8101/build/vendor.js:1477:90)
    at noProviderError (http://localhost:8101/build/vendor.js:1515:12)
    at ReflectiveInjector_._throwOrNull (http://localhost:8101/build/vendor.js:2957:19)
    at ReflectiveInjector_._getByKeyDefault (http://localhost:8101/build/vendor.js:2996:25)
    at ReflectiveInjector_._getByKey (http://localhost:8101/build/vendor.js:2928:25)
    at ReflectiveInjector_.get (http://localhost:8101/build/vendor.js:2797:21)
    at resolveNgModuleDep (http://localhost:8101/build/vendor.js:9797:25)
    at NgModuleRef_.get (http://localhost:8101/build/vendor.js:10885:16)
    at resolveDep (http://localhost:8101/build/vendor.js:11388:45)
    at createClass (http://localhost:8101/build/vendor.js:11252:32)
    at c (http://localhost:8101/build/polyfills.js:3:19132)
    at Object.reject (http://localhost:8101/build/polyfills.js:3:18554)
    at NavControllerBase._fireError (http://localhost:8101/build/vendor.js:43919:16)
    at NavControllerBase._failed (http://localhost:8101/build/vendor.js:43907:14)
    at http://localhost:8101/build/vendor.js:43962:59
    at t.invoke (http://localhost:8101/build/polyfills.js:3:14356)
    at Object.onInvoke (http://localhost:8101/build/vendor.js:4198:33)
    at t.invoke (http://localhost:8101/build/polyfills.js:3:14296)
    at r.run (http://localhost:8101/build/polyfills.js:3:9523)
    at http://localhost:8101/build/polyfills.js:3:19622
`
1 resposta

Boa tarde, Ricardo! Como vai?

O log de erro diz o seguinte:

Error: No provider for CarrosServiceProvider!

Então, meu chute é que vc deve ter esquecido de adicionar o CarrosServiceProvider na lista de providers no módulo principal da aplicação!

Dá uma conferida nisso! Qualquer coisa é só falar!

Grande abraço e bons estudos, meu aluno!