1. 怎么在多个component中使用 自定义管道
先建好管道
import {Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'subStr' }) export class SubStrPipe implements PipeTransform { transform(str: string, num: number): string { if(str.length > num){ return str.substring(0, num) + '...'; }else{ return str; } } }
然后再随便哪一个,最好的等级高一点的module中去定义它,我这里直接两个管道一期定义了。
最重要的是在
declarations
exports
两个地方加上管道名
@NgModule({ declarations: [ SubStrPipe, TimeZonePipe, DialogElementsExampleComponent ], imports: [ RouterModule.forChild(routes), ], exports: [ SubStrPipe, TimeZonePipe ], entryComponents: [ DialogElementsExampleComponent ] }) export class TeacherModule { }
2. 让组件component在不同的moudle中可以引用,
如上图,
DialogElementsExampleComponent
所在的位置,
declarations
entryComponents
这两个位置家进去
-----------------------------------以上的内容全部都是在父组件,也就是上面提到的高级一点的module
然后,我们在哪里需要用到它,就在那个moudle中
import进来就可以了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。