Brandon
Brandon

Reputation: 1409

How to do JavaScript Library Dependency Injection in Angular?

How can I include JavaScript libraries on a controller basis using Angular?

For example, I'm using morris.js and ckeditor in this project which require nearly 1MB (dev versions) of resources even though they are only used on two pages.

It's obviously a waste to include these within the entire single page application by referencing them in the index.html file.

Is there a way to use Angular Dependency Injection to include these in a controller? I'm guessing using a service or a directive but I'm not sure how those components would look in this case.

Upvotes: 0

Views: 209

Answers (1)

Gjohn
Gjohn

Reputation: 1281

You are better off using require.js to load these modules in your SPA based on when you need them.

Upvotes: 2

Related Questions