我可以建立全局注册管道,保护全局访问吗? [英] Can I make global registration pipe, guard for global access?
问题描述
有人可以向我解释.我可以在主模块中注册管道,防护装置以访问另一个模块. 例子
Could someone explain me. Can I registration pipes, guards only in main module for access another module. Example
我有主模块和用户模块.我在主模块中注册的用户模块.在用户模块中,我使用管道在其中注册用户组件.我可以仅在主模块中注册此管道,还是必须在用户模块中注册?
I have main module, and user module. User module I register in main module. In user module I register user component where I using pipe. Can I registration this pipe only in main module, or I must registration in user module?
推荐答案
要在Angular2中添加管道,您不再需要在装饰器中实现它.
- 制作一个单独的文件,该文件将保存管道的代码,例如:
anyPipe.pipe.ts
它看起来像:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'anyPipe'
})
export class anyPipe implements PipeTransform {
//pipe logic
}
-
将其添加到您的
app.module.ts
文件中:
Add it into your
app.module.ts
file:
import { anyPipe } from './anyPipe.pipe'; @NgModule({ declarations: [ anyPipe ] })
-
现在,您必须将管道导入到组件的模块文件中,例如:
Now you have to import the pipe into your component's module file, e.g.:
user.module.ts
user.module.ts
import { anyPipe } from '~pathToPipe~/anyPipe.pipe'; @NgModule({ declarations: [ anyPipe ] })
-
然后就可以在组件中的任何位置使用它:
Then just use it wherever you want in your component:
<ul *ngFor="let elem of elems | anyPipe">
这篇关于我可以建立全局注册管道,保护全局访问吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
-