Is it possible to load plain old JS or AMD modules from an Angular Controller? I have previously used RequireJS for this.
I have used AngularJS and RequireJS on a fairly large project before. I am working on a new project based on the MEAN Stack seed, and this does not use requireJS.
I am not entirely clear, but Angular has a system for loading modules -- can I load a particular piece of javascript from within my angular controller?
Is there a way to modify my module() declaration to include additional regular javascript files?
Thanks!
EDIT: To give a bit of understanding on what I am doing, I have a page that edits a few different forms. Each of these is saved into my database as a "form". Depending on the type of form, different dictionary values are mapped to different fields in different sub-views. Some of my forms have e.g dropdowns or lists of inputs. These are different, but everything else about the 'form' is handled in a generic way.
So I have this singular form controller that handles a bunch of different forms, and I am very happy with the result. The main issue comes from that each form has a separate set of data I would like to avoid loading unless I need.
I can check which form I am loading by checking my dropdown that drives my ng-include (which loads the subform).
In the short term I have just loaded everything and created namespaces under my scope to differentiate.
e.g $scope.form1 and $scope.form2 for data/rules specific to a particular form. I'd just as soon rather not load the js that I don't need.
Edit 2: http://jsfiddle.net/HB7LU/1320/
function MyCtrl($scope) {
$scope.doSomething = function()
{
//I'm used to wrapping with e.g require('jquery..... here, can I do the same thing with angular?
alert(" I need to run a jquery function here...");
var xml = $(someblock);
};
}
I've put up a fiddle with exactly what I am talking about. I want to load arbitrary JS depending on certain paths in my controller, and only when I need them.
Basically I have some larger namespaces I want to load depending on one of many options selected, and it would be expensive to just load them all.