2017-07-27 61 views
0

這是我的第一篇文章,所以如果我沒有遵循一些規則,我很抱歉。 這篇文章的標題可能會敲響一個鐘,因爲我查看了周圍的所有結果,但無法找到問題的根本原因。未被捕獲(承諾):錯誤:模板解析錯誤:無法找到管道'鑰匙'

我有一個模式,打開顯示一個窗體,其中我有一個選擇將列出選項從一個枚舉。我正在將一個管道應用於此枚舉以使該對象成爲一個數組。

但我得到的管道'鑰匙'找不到問題。

我非常感謝您的幫助!

所以我app.module.ts

import { ErrorHandler, NgModule } from '@angular/core'; 
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; 
import { WaitingTime, YearsAgo, SortBy, KeysPipe} from '../pipes/mypipe'; 
import { MyApp } from './app.component'; 
import { HomePage } from '../pages/home/home'; 

@NgModule({ 
    declarations: [ 
    MyApp, 
    HomePage, 
    WaitingTime, 
    YearsAgo, 
    SortBy, 
    KeysPipe //declaring my pipe here 
    ], 
    imports: [ 
    BrowserModule, 
    IonicModule.forRoot(MyApp) 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp, 
    HomePage 
    ], 
    providers: [ 
    {provide: ErrorHandler, useClass: IonicErrorHandler}, 
    MyDateListService  
    ] 
}) 
export class AppModule {} 

然後我的主頁home.ts(將不遺餘力一些不必要的線條)。 這是從何處打開模態。

import { Component } from '@angular/core'; 
import { NavController, ModalController, AlertController, ItemSliding} from 
'ionic-angular'; 
import {DateFormPage} from '../date-form/date-form' 
import {WaitingTime, YearsAgo} from '../../pipes/mypipe'; 
import {MyDates } from '../../models/my-dates'; 
import {MyDateListService} from '../../services/date-list' 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 

export class HomePage {} 

打開日期form.ts 中,我需要管的功能

import { Component, OnInit } from '@angular/core'; 
import { IonicPage, NavController, NavParams, ViewController } from 'ionic- 
angular'; 
import {NgForm, FormBuilder, FormControl, FormGroup, Validators} from 
'@angular/forms' 
import { MyDateListService } from '../../services/date-list'; 
import {KeysPipe} from '../../pipes/mypipe'; //here is the pipe 
import {DateTypes} from '../../models/enums'; 

@IonicPage() 
@Component({ 
    selector: 'page-date-form', 
    templateUrl: 'date-form.html' 
}) 

export class DateFormPage implements OnInit {} 

最後我管mypipe.ts

import {Pipe, PipeTransform} from '@angular/core'; 

//declaring all my pipes 
@Pipe ({ 
    name:'waitingTime' 
}) 

export class WaitingTime implements PipeTransform 
{ } 
[.... all the other pipes] 

// and this is the pipe that is not found. 
@Pipe ({ 
    name: 'keys', 
    pure: false 
}) 

export class KeysPipe implements PipeTransform { 

    transform(value: any, args: any[] = null): any { 
     return Object.keys(value).map(key => value[key]); 
    } 
} 
+0

WaitingTime管道是否正常工作?此外,錯誤來自哪個頁面? – SimplyComplexable

+0

我在模塊中看不到'DateFormPage'。 – acdcjunior

+0

@ZackSunderland是的所有其他管道被發現和工作正常(在主頁中使用 – Jojo

回答

1
模態頁

好的,我終於找到了我的錯誤,可能是因爲還有點菜鳥,沒有注意到pa由離子自動創建的ges。

我試圖讓@NgModule我日期form.ts時,我已經有了一個日期form.module.t是我近來的模塊定義。 所以宣佈我的管道,並從其他模塊app.module.ts取消它的聲明使它的工作。

感謝您的所有評論,他們引導我瞭解我的問題的來源。

相關問題