Why should I define a controller in the constructor?


#1

For example, https://ionicframework.com/docs/api/components/toast/ToastController/

import { ToastController } from 'ionic-angular';
constructor(private toastCtrl: ToastController) {
}

presentToast() {
  let toast = this.toastCtrl.create({

Can I use ToastController without defining in the constructor?


#2

No, I don’t think so. That’s how Angular’s dependency injection works. You can read about it in the Angular docs.