2017-01-16 34 views
1

這是movie-info.html我的代碼:Ionic2未處理的承諾拒絕:模板解析錯誤:「離子項目內容」是不是一個已知的元素:錯誤

<ion-header> 
<ion-navbar> 
    <ion-title> 
    Movie Info 
    </ion-title> 
</ion-navbar> 
</ion-header> 

<ion-content class="home" padding> 
    <div *ngIf="movie" class="selection"> 
    <ion-card> 
     <ion-item> 
      <ion-avatar item-left> 
       <img src="path/to/image{{movie-poster}}"/> 
      </ion-avatar> 
      <ion-item-content class="movie-title-data"> 
       <h1>{{movie.title}}</h1> 
       <p>{{movie.release_date}}</p> 
      </ion-item-content> 
     </ion-item> 

     <ion-item> 
      <icon document item-left></icon> 
      <h2>Overview</h2> 
      <p class="item-description">{{movie.overview}}</p> 
     </ion-item> 
     <ion-item> 
      <icon bookmark item-left></icon> 
      <h2>Average Vote</h2> 
      <p>{{movie.vote_average}}</p> 
     </ion-item>  
    </ion-card> 
    </div> 
</ion-content> 

這是錯誤我得到:

Unhandled Promise rejection: Template parse errors: 
'ion-item-content' is not a known element: 
1. If 'ion-item-content' is an Angular component, then verify that it is part of this module. 
2. If 'ion-item-content' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("path/to/image{{movie-poster}}"/> 
      </ion-avatar> 
      [ERROR ->]<ion-item-content class="movie-title-data"> 
       <h1>{{movie.title}}</h1> 
     "): [email protected]:16 

'icon' is not a known element: 
1. If 'icon' is an Angular component, then verify that it is part of this module. 

所有元素都會出現類似的錯誤。

這是movie-info.ts

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

@Component({ 
    templateUrl: 'movie-info.html' 
}) 

export class MovieInfoPage { 

    movie: {}; 

    constructor(private navController: NavController, private navParams: NavParams) { 
    this.movie = navParams.get('movie'); 
    } 
} 
+0

所以你的'MovieListPage'沒有選擇器? – echonax

+0

@echonax我不明白你的意思。這是我第一次使用Ionic2。 :) –

+0

在您的'@ Component'註釋裏'templateUrl'和'providers'是,你需要有一個'selector'來引用組件作爲一個元素。但我對離子的瞭解不多,可能會有所不同。 'MovieInfoPage'和'MovieListPage'之間的關係是什麼? – echonax

回答

1

爲模板錯誤:

因爲它表明ion-item-content不離子2. 我建議使用一個div,而不是一個有效的標籤。

ion-item component

+0

其實,文件名是'movie-info.ts'。我在這個問題上犯了一個錯誤。 –

+0

好的..現在你正在'找不到組件工廠'或解析錯誤? –

+0

我很抱歉混淆蘇拉傑。我正在編輯的問題更清楚。我誤解了我收到的錯誤。抱歉。 –

相關問題