2017-07-27 82 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取消它的声明使它的工作。

感谢您的所有评论,他们引导我了解我的问题的来源。

相关问题