【问题标题】:Can't resolve all parameters for Modal: (?, ?, ?)无法解析 Modal 的所有参数:(?, ?, ?)
【发布时间】:2016-11-27 04:59:33
【问题描述】:
import { Component, Inject } from '@angular/core';
import { NavController, Modal } from 'ionic-angular';

import { PopupPage } from '../../components/modal/modal.page';

@Component({
  templateUrl: 'build/pages/spot/spot.html',
  providers: [ Modal ]
})
export class SpotComponent {

  constructor(@Inject(Modal) private modal: Modal ) {}
}

【问题讨论】:

  • 你能把modalcomponent的代码放在这里吗。问题出在 modalcomponent 的构造函数中。
  • 它是一种离子成分。这不是我的代码。
  • 好吧。错误说它在模态启动时找不到模态所需的依赖项。
  • 我很确定 Modal 不是要注入的。查看docs 似乎总是要使用Modal.create 构建模态。我相信 Angular 正在尽最大努力为您构建一个,但由于 Modal 没有无参数构造函数并且没有标记为@Injectable,它几乎无能为力。你想解决什么问题?
  • 另外,在同一行中,Modal 并不是提供者,也不应该在您的提供者数组中。

标签: angular typescript ionic-framework ionic2 ionic3


【解决方案1】:

就像@Pace 评论的那样,您可以查看Ionic2 docs 以了解如何创建 Modal

您不必像现在这样将它包含在providers 数组或constructor 中。相反,您应该像这样使用Modal.create(...) 方法:

import { Modal, NavController, NavParams } from 'ionic-angular';

@Component(...)
class HomePage {

 constructor(/* ..., */ private nav: NavController) {
   // Your code...
 }

 presentProfileModal() {
   // Create the modal using the layout from the Profile Component
   let profileModal = Modal.create(Profile, { paramId: 12345 });

   // Show the modal
   this.nav.present(profileModal);
 }

}

@Component(...)
class Profile {

 constructor(/* ..., */ private params: NavParams) {
   // Get the parameter by using NavParams
   console.log('paramId', params.get('paramId'));
 }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 2017-09-26
    • 2018-03-24
    • 1970-01-01
    • 2018-05-16
    • 2017-11-04
    • 2017-07-27
    相关资源
    最近更新 更多