Hi, My code is not new and most of the code is copied from http://weblogs.asp.net/dwahlin/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs
It acts as useful code snippet for myself and anyone who is looking for one.
I adapted the code to load the js files using JQuery instead of RequireJS, and it follows predefined naming convention for url, templates and js files:
- Url and file name: all small letters with each word separated with - (hyphen).
- Controller name: first letter of each word is caps with no gaps and ends with 'Ctrl'.
RouteProvider takes care of dynamically loading of js controller files using Jquery:
Register the controller (view3.js) after load with $controllerProvider:
view3.html template code:
Libraries used: jquery, angularjs v1.4 and angular-route