【发布时间】:2018-01-03 12:17:54
【问题描述】:
这是我的第一篇文章,所以如果我不遵守某些规则,我深表歉意。 这篇文章的标题可能敲响了警钟,因为我查看了它周围的所有结果,但找不到问题的根本原因。
我有一个模式,可以打开以显示一个表单,在该表单中我有一个选择,它将列出枚举中的选项。我正在对这个枚举应用一个管道以使该对象成为一个数组。
但我遇到了管道“键”未找到问题。
非常感谢您的帮助!
所以我的 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 {}
打开 date-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]);
}
}
【问题讨论】:
-
WaitingTime 管道工作正常吗?还有错误来自哪个页面?
-
我没有看到模块中声明的
DateFormPage。 -
@ZackSunderland 是的,之前声明的所有其他管道都已找到并且工作正常(在主页中使用。
-
@acdcjunior DateFormPage 加载并且运行良好(当没有管道时)如果您的意思是在 app.module.ts 中?已经尝试过了,它给了我这个错误:未捕获(承诺):错误:类型 DateFormPage 是 2 个模块声明的一部分:AppModule 和 DateFormPageModule!已经在 home.ts 中导入了
-
@Jojo 究竟是什么错误,它来自哪个页面?