【问题标题】:Error: Uncaught (in promise): invalid link: ProductListComponent错误:未捕获(承诺):无效链接:ProductListComponent
【发布时间】:2021-04-17 02:57:42
【问题描述】:

我仍然在学习角度,离子和我很困惑我的错在哪里,我一直在寻找另一个问题,但我仍然不明白,你们能帮我吗?也许你有一些代码可以清楚地解释它?

这是我的 product-list.component.ts

    import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@Component({
  selector: 'page-prod-list-view',
  templateUrl: 'product-list.component.html',
  styleUrls: ['product-list.component.css']
})

export class ProductListComponent {
  products = [
    {
      name: 'Phone XL',
      price: 799,
      description: 'A large phone with one of the best screens'
    },
    {
      name: 'Phone Mini',
      price: 699,
      description: 'A great phone with one of the best cameras'
    },
    {
      name: 'Phone Standard',
      price: 299,
      description: ''
    }
  ];

  share() {
    window.alert('The product has been shared!');
  }

  view() {
    window.alert('The product has been viewed!');
 }
}

这是我的 product-list.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { ProductListComponent } from './product-list.component';

@NgModule({
  declarations: [
    ProductListComponent
  ],
  imports: [
    IonicPageModule.forChild(ProductListComponent),
  ],
  exports: [
    ProductListComponent
  ]
})
export class ProductListModule { }

这是我的html

<h2>Products</h2>

<div *ngFor="let product of products">
    <h3>
        <a [title]="product.name + ' details'">
            {{ product.name }}
        </a>
    </h3>

    <p *ngIf="product.description">
        Description: {{ product.description }}
    </p>

    <button (click)="share()">
        Share
    </button>

    <button (click)="view()">
        View
    </button>

</div>

【问题讨论】:

  • 构造函数和ngOnInit在哪里?
  • 您必须描述您的错误。什么时候发生?什么除外? ...

标签: javascript angular ionic-framework


【解决方案1】:

你好像错过了什么。

import { IonicPage, NavController, NavParams } from 'ionic-angular';

你导入了 IonicPage 装饰器,但在之前没有调用装饰器

@Component 装饰器。您需要在@Component() 之前调用@IonicPage() 来注册并在URL 中显示页面。

应该是这样的

@IonicPage()
@Component({
  selector: 'page-prod-list-view',
  templateUrl: 'product-list.component.html',
  styleUrls: ['product-list.component.css']
});

由于您的组件未注册,因此您收到以下错误。

您可以在

中查看更多详细信息

https://ionicframework.com/docs/v3/api/navigation/IonicPage/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-17
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    相关资源
    最近更新 更多