0

I want to use Angular Material's Drag and Drop feature in my app.

I don't want to initially load it, but only when I use drag and drop feature in a specific component.

I know how to lazy load modules in routes, but don't know how to lazy load a library.

Thanks.

1 Answer 1

1

It depends how your project is structured. If your component is the only component in the related module then you can load the Drag & Drop module only for the component but if you have multiple components under the same module then you have to restructure and create a module for the component and import the Drag & Drop there.

import {DragDropModule} from '@angular/cdk/drag-drop'; 
@NgModule({
  ...
  declarations: [AppComponent],
  imports: [
    DragDropModule,
    ...
  ],
  ...
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Maihan for the reply. Now I understood how we can do lazy loading of a 3rd party library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.