проблемы с просмотром деталей в Ionic 4 - PullRequest
0 голосов
/ 10 июня 2019

В одном из моих проектов я пытаюсь создать список элементов, и после того, как пользователь нажмет на элемент, они перейдут на новую страницу, где будут показаны детали элемента.Это очень просто и понятно, название Предмета и его детали уже написаны на первой странице, и я хочу, чтобы они были перенесены на следующую страницу.Однако я продолжаю получать сообщение об ошибке: Argument of type '{ item: any; }' is not assignable to parameter of type 'NavigationOptions

вот мой код следующим образом: Это главная страница, на которой будет показан список всех элементов

HTML

<ion-list>
<ion-item *ngFor="let item of items" (click)="viewItem(item)"><ion-card>
<ion-card-header>
<ion-card-subtitle></ion-card-subtitle>
<ion-card-title>{{item.title}}</ion-card-title>
</ion-card-header>

<ion-card-content>
{{item.description}}
</ion-card-content>
</ion-card></ion-item>
</ion-list>

TS

export class ShoppingPage implements OnInit {
  public item;
  constructor( public navCtrl: NavController ) { }

  ngOnInit() {
  }
  ionViewWillEnter(){
  this.item = [
      {title: 'Product 1', description: 'This is where we would would put the description of "product 1"'},
      {title: 'Product 2', description: 'This is how the description of Product 2 would look'},
      {title: 'Product 3', description: "Product 3 is the greatest product you can buy off the market because it's perfect"}
    ];
  }
  viewItem(item){
    this.navCtrl.navigateForward('item-detail', {
      item: item
    });
  }

}

Теперь вот код страницы, на которой мне требуется показать все данные:

HTML

<ion-header>
  <ion-toolbar>
    <ion-title>{{title}}</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
{{description}}
</ion-content>

TS

export class ItemDetailPage implements OnInit {
  title;
  description;
  constructor(public navParams: NavParams) { }
  ionViewDidLoad(){
    this.title = this.navParams.get('item').title;
    this.description = this.navParams.get('item').description;
  }
  ngOnInit() {
  }

}

Спасибо

РЕДАКТИРОВАТЬ: я использую ионный4

1 Ответ

0 голосов
/ 10 июня 2019

В вашем первом файле TS

public item;

до

public items;

и

this.item = [ {title: 'Product 1', description: 'This is where we would would put the description of "product 1"'}, {title: 'Product 2', description: 'This is how the description of Product 2 would look'}, {title: 'Product 3', description: "Product 3 is the greatest product you can buy off the market because it's perfect"} ]; }

до

this.items = [ {title: 'Product 1', description: 'This is where we would would put the description of "product 1"'}, {title: 'Product 2', description: 'This is how the description of Product 2 would look'}, {title: 'Product 3', description: "Product 3 is the greatest product you can buy off the market because it's perfect"} ]; }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...