How to share a package (ngx-lottie) across the whole Angular project, and accessible from all components?

Viewed 27

I am using Angular 13, and I just downloaded ngx-lottie which I want to use in each component while loading data...

My question is how can I make it accessible to all components? without the need to import it.

What I've done: Downloaded this: https://www.npmjs.com/package/ngx-lottie

In my module (I'm thinking of a shared module, but what are the best practices)?

import { LottieModule } from 'ngx-lottie';
import player from 'lottie-web';

And I'm not sure what the player is?

then I added this code

export function playerFactory() {
  return player;
}

Imports:

 LottieModule.forRoot({ player: playerFactory })

Also whats this? forRoot and player?

Exports:

LottieModule

Now should I import the options in each component? or is there another way?

import { AnimationOptions } from "ngx-lottie";
0 Answers
Related