[英]Error: Uncaught (in promise): invalid link: ProductListComponent
我還在學習 angular,離子和我很困惑我的錯在哪里,我一直在尋找另一個問題,但我仍然不明白,你們能幫幫我嗎? 也許你有一些代碼可以清楚地解釋它?
這是我的 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>
好像你錯過了什么。
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/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.