Ionic 2 "Can't resolve all parameters" when importing a component

Viewed 3068

My home component has functions to operate on my main array of list items. I am trying to access these functions through another component called item-details.

However, when I import the HomePage component, and add it to the constructor for item-details.ts, I get the following error:

"Runtime Error Can't resolve all parameters for ItemDetailPage: ([object Object], [object Object], ?)".

error image

item-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
  }
}

And here is a picture of my file structure in case it is relevant. file structure

What's wrong and how can I fix it?

1 Answers
Related