I have noticed a few questions that are similar to this one, but my question has a slight variation.
In my controller, I have an object that resembles the following:
$scope.data = {
foo: {bar: 1,
bas: 2},
biz: 3,
blat: 4
};
My goal is to create an input field where the ng-model can be dynamically assigned to any of those values.
<label>Define Model</label>
<input type="text" ng-model="input.model" />
<label>Data for {{input.model}}:</label>
<input type="text" ng-model="{{input.model}}">
Essentially, I would like to be able to set the "Define Model" input to something like data.foo.bas
and have the corresponding "Data for data.foo.bas" input display a value of 2.
I am aware that I can achieve a similar result with the following code:
<label>Define Model</label>
<input type="text" ng-model="input.model" />
<label>Data for {{input.model}}:</label>
<input type="text" ng-model="data[input.model]">
However, this method only allows me to access the biz and blat attributes. Does anyone have any suggestions on how this can be accomplished? Thank you.