无法解析ModalPage的所有参数:([对象对象],[对象对象],?,[对象对象])

时间:2018-09-30 07:56:10

标签: angularjs ionic3

我正在使用Ionic 3.9.2并在触发模态模板时遇到此错误:

Uncaught Error: Can't resolve all parameters for ModalPage: ([object Object], [object Object], ?, [object Object]).

此类具有函数openModal,该函数打破了上述错误:

import { Component, NgZone } from "@angular/core"
import { NavController, Platform, ModalController } from 'ionic-angular';
import { HTTP } from '@ionic-native/http';
import { ModalPage } from './../modal/modal';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class Component{
  todoItems: object[];
  constructor(
    public navCtrl: NavController,
    public platform: Platform
    public modalCtrl: ModalController
  ) {}

openModal() {
    //This line throws the error
    let modal = this.modalCtrl.create(ModalPage);
  }

}

我确切地缺少哪个角度依赖性?

1 个答案:

答案 0 :(得分:0)

constructor(
    public navCtrl: NavController,
    public platform: Platform
   @Inject(ModalController) public modalCtrl: ModalController
  ) 

有了这个,您对编译器说丢失的类将在以后注入。

此外,重要的是要说ModalPage本身应该用@Injectable()装饰。

@Injectable()
export class ModalPage{
// ... your code
}