【发布时间】:2018-03-01 09:23:52
【问题描述】:
我已经建立了一个管道,但我不知道为什么 angular 找不到它。
我的*模块是我的 shared.module
该模块又由 browser.module 或 server.module 集成。
此外,我有一个 user.module 作为最低级别,所有用户的组件都进来。
如果我在 user.module 中定义我的管道,就会找到该管道。
import { ExponentialStrengthPipe } from '../../exponential-strength.pipe';
[...]
@NgModule({
declarations: [ [...]
ExponentialStrengthPipe
],
imports: [
CommonModule,
HttpModule,
FormsModule,
ReactiveFormsModule,
RouterModule.forChild([...])
],
})
export class UserModule {
constructor(
) {
}
}
如果我将它安装在我的共享中。模块,不再赘述。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ExponentialStrengthPipe } from './exponential-strength.pipe';
[...]
@NgModule({
declarations: [
AppComponent,
[...]
ExponentialStrengthPipe
],
providers: [
UserService
],
imports: [
CommonModule,
RouterModule.forRoot([
{ path: 'home', component: HomeComponent },
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent },
]),
],
exports: [
ExponentialStrengthPipe
]
})
export class AppModuleShared {
constructor(
) {
}
}
【问题讨论】:
-
如果你在
UserModule之外使用管道,你需要将UserModule添加到你想使用它的模块的imports: [...]中。
标签: angular pipe angular-pipe