I'm trying to bind the value of an input field to a variable.
I don't know the name of this variable a priori; it is stored in another variable.
This is the html:
<body ng-controller=stageController>
<form name=myForm novalidate=>
<input type=text name=myText ng-model=model />
</form>
</body>
and this is the controller:
function stageController($scope) {
$scope.model = 'realModel'; // contains the name of the variable that i would bind to the field
$scope.realModel = 'initial value of the field';
}
I made also a fiddle.
This doesn't work because currently the binding is between the input field and the model
variable. Instead I would bind the input field to the variable which name is stored inside the $scope.model
variable (in this case realModel
).
Is it possible? How?