I am building an Angular library to use in a bigger project. It's going to be a multi-repo approach, with each of the parts of the app being a library. All of that parts are going to have their components, pipes, services...
But my first tests are not working. I created my standalone library and a hello-world component, built it with --watch, linked it with NPM to my base project... and it works. It shows the message on the screen. The problem comes when I try to add a pipe of any kind, even default pipes break. If create a Date object and use the date pipe after the message, it breaks. Same with currency or async pipes.
Error for date pipe:
Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[DatePipe -> InjectionToken LocaleId]:
StaticInjectorError(Platform: core)[DatePipe -> InjectionToken LocaleId]:
NullInjectorError: No provider for InjectionToken LocaleId!
Error: StaticInjectorError(AppModule)[DatePipe -> InjectionToken LocaleId]:
StaticInjectorError(Platform: core)[DatePipe -> InjectionToken LocaleId]:
NullInjectorError: No provider for InjectionToken LocaleId!
...
Error for async pipe:
Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[AsyncPipe -> ChangeDetectorRef]:
StaticInjectorError(Platform: core)[AsyncPipe -> ChangeDetectorRef]:
NullInjectorError: No provider for ChangeDetectorRef!
Error: StaticInjectorError(AppModule)[AsyncPipe -> ChangeDetectorRef]:
StaticInjectorError(Platform: core)[AsyncPipe -> ChangeDetectorRef]:
NullInjectorError: No provider for ChangeDetectorRef!
at NullInjector.push.../../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:8896)
...
The library module looks like this:
@NgModule({
declarations: [HolaMundoTestComponent],
imports: [
CommonModule
],
exports: [HolaMundoTestComponent]
})
export class HolaMundoTestModule { }
And the component it exports:
@Component({
selector: 'lib-hola-mundo-test',
// templateUrl: './hola-mundo-test.component.html',
// template: `<h1>Hola mundo en fecha {{ dateFrom | date }}</h1>`,
template: `<h1>Hola mundo en fecha {{ text | async }}</h1>`,
styleUrls: ['./hola-mundo-test.component.scss']
})
export class HolaMundoTestComponent {
public text = new BehaviorSubject<string>('MITEXTO');
public dateFrom = new Date();
public money = 123245.234555;
// constructor(public holaMundoTest: HolaMundoTestService) {}
}
Any ideas? I'm importing the CommonModule that holds all those default pipes and it's the tiniest library possible.