0

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.

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Interesting, thanks for the answer. After reading more about require.js and Angular that seems to be the best approach.
Glad I could help, Brandon. Good luck with your application.

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.