question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using custom pipes in lazy modules

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Custom pipes declared in the main app module are not seen in the lazy module components - “Pipe xxx could not be found…” error. If the pipes are declared in the lazy module instead angular behaves as expected. Expected behavior

Declarations of top level modules should propagate to all components. Please tell us about your environment:

os x

  • Angular version: 2.0.X 2.01
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ] any
  • Language: [all | TypeScript X.X | ES6/7 | ES5] 2.0
  • Node (for AoT issues): node --version =
    6.7

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

25reactions
homofortiscommented, Oct 12, 2016

Oh man, this framework is really becoming over-complicated for a web frontend. If this keeps on going it may die of sophistication fatigue 😛

10reactions
RoxKillycommented, Oct 12, 2016

This is expected behavior. The template parser will recognize a directive, component or pipe if and only if it was listed in the declarations array of the current NgModule or exported by a module that the current NgModule imports.

If you wish for your pipe to be accessible from multiple modules, declare it in a module that will be imported by the others. For instance, you could have a SharedModule that exports all directives, components and pipes that you want to share.

@NgModule({
    imports: [CommonModule],
    exports: [SharedPipe, SharedDirective, SharedComponent]
})
export class SharedModule{
    static forRoot() {
        return {
            ngModule: SharedModule,
            providers: [ //services that you want to share across modules
                SharedService,
                SharedService2
            ]
        }
    }
}

Your root AppModule should list SharedModule.forRoot() in its imports array. Your other modules (including lazy-loaded modules) should list SharedModule in their imports arrays.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can we import Pipe file in different Lazy Loading Pages ...
I create pipe using this CLI : ionic generate pipe MyFilter. Then it'll create pipes.module.ts automatically. After that, I just import it ...
Read more >
Adding Components, Pipes and Services to a Module
In this chapter we are going to extend the example we had before with a custom component, pipe and service. Let's start by...
Read more >
Pipe not found (lazy loaded pages - using Josh Morony's ...
I'm trying to implement a pipe that I can use in the template, within ngFor but I just can't get past The pipe...
Read more >
Angular 2 Tutorial => Custom Pipes
Learn Angular 2 - Custom Pipes. ... import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'myPipe'}) export class MyPipe ... my.module.ts
Read more >
How to Build Custom Pipes in Angular - Coding Latte
Now, you can just import the module in any lazy loaded module you want to use the pipes in. @NgModule({ declarations: [AppComponent], imports:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found