【问题标题】:trouble viewing item details in Ionic 4在 Ionic 4 中查看项目详细信息时遇到问题
【发布时间】:2019-06-10 00:30:33
【问题描述】:

在我的一个项目中,我试图创建一个项目列表,一旦用户按下某个项目,他们将被导航到一个新页面,该页面将显示该项目的详细信息。非常简单明了,项目的名称和详细信息已经写在第一页,我希望将它们转移到下一页。但是我不断收到错误消息: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() {
  }

}

谢谢

编辑:我正在使用 ionic 4

【问题讨论】:

    标签: ionic-framework ionic4 listitem


    【解决方案1】:

    在您的第一个 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"} ]; }

    【讨论】:

    • 现在我有两个错误。一个是我不断收到的错误,另一个是Argument of type Object literal may only specify known properties, and 'items' does not exist in type 'NavigationOptions'
    • 这一行` viewItem(item){ this.navCtrl.navigateForward('item-detail', { item: item }); } ` 那里错了
    • 你能帮我弄清楚什么吗? item-detail 是我试图导航到并传输数组数据的页面。
    猜你喜欢
    • 2020-10-15
    • 1970-01-01
    • 2020-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多