我的家庭組件具有對我的主要列表項目進行操作的功能。我試圖通過稱爲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/ –