I'm sticking my toe in the Angular ocean. I have a web application that uses jQuery to allow the user to interact with the application using input forms and buttons. I'm learning Angular and as an exercise, I decided to try to write code to do this with Angular instead.
<body ng-app="myApp" ng-controller="MainFormCtrl as Form">
I used the ng-app
and ng-controller
directives as above to make my application use an Angular controller I've written.
I use the ng-model
directive with each input the user can enter data into. I use the form ng-model="Form.inputs.xxxxx"
because I want to be able to pass around the collection of input values as a single object.
I have written code in my controller that provides default values for these inputs. I am still using my existing code to read the values from the DOM. I understand that once I've declared my model and controller, Angular magically allows me to pass around the model so that I can read it and make changes to it elsewhere in my program.
I've attached a method called getInputs
to my Angular controller. How can I call this member function (or get other members of the controller object) from non-Angular code? If that isn't practical, what sort of solution should I use.
Form.inputs.xxxxx
, Angular will automatically create a variable in it's$scope
object to track changes to that model. Your controller would have access to$scope.Form.inputs.xxxxx
as a value, two way bound. – Claies May 26 at 0:32inputs
would just be a property of your controller, soinputs.xxxxx
would work, without using$scope
. – Claies May 26 at 0:43