我的家庭组件具有对我的主要列表项目进行操作的功能。我试图通过称为item-details的另一个组件访问这些函数。导入组件时,Ionic 2“无法解析所有参数”
但是,当我导入HomePage组件,并将其添加到item-details.ts的构造函数时,出现以下错误:“运行时错误无法解析ItemDetailPage的所有参数:[[object Object], [object object],?)“。 error image
项目-details.ts:
import { Component } from '@angular/core';
import { NavParams, NavController } from 'ionic-angular';
import { HomePage } from '../home/home';
@Component({
selector: 'page-item-detail',
templateUrl: 'item-detail.html'
})
export class ItemDetailPage {
title;
description;
constructor(
public navParams: NavParams,
public navController: NavController,
public home: HomePage
){
}
ionViewDidLoad() {
this.title = this.navParams.get('item').title;
this.description = this.navParams.get('item').description;
}
deleteItem(item){
//call deleteItem in home.ts
}
}
home.ts:
import { Component } from '@angular/core';
import { ModalController, NavController, ViewController } from 'ionic-angular';
import { AddItemPage } from '../add-item/add-item'
import { ItemDetailPage } from '../item-detail/item-detail';
import { Data } from '../../providers/data/data';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public items = [];
constructor(
public navCtrl: NavController,
public modalCtrl: ModalController,
public dataService: Data
) {
this.dataService.getData().then((todos) => {
if(todos){
this.items = JSON.parse(todos);
}
});
}
ionViewDidLoad(){
}
addItem(){
let addModal = this.modalCtrl.create(AddItemPage);
addModal.onDidDismiss((item) => {
if(item){
this.saveItem(item);
}
});
addModal.present();
}
saveItem(item){
this.items.push(item);
this.dataService.save(this.items);
}
viewItem(item){
this.navCtrl.push(ItemDetailPage, {
item: item
});
}
deleteItem(item){
//code to delete an item from items array
}
}
这里是我的文件结构的情况下画面它是相关的。 file structure
任何人都可以帮我弄清楚什么是错的,以及如何解决它?
你可以尝试在plnkr中重新创建问题,没有任何东西是不正确的。 http://embed.plnkr.co/SJ8GtqbRntby5yGzLEft/ –