I have seen several questions similar to this but my question is slightly different.
I have an object on my controller that looks something like this:
$scope.data = {
foo: {bar: 1,
bas: 2},
biz: 3,
blat: 4
};
I would like to create an input that can have its ng-model 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}}">
Ideally this would allow me to set the "Define Model" input to something like data.foo.bas
and the "Data for data.foo.bas" input would have a value of 2.
I am aware I can do something like this:
<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]">
but this would only allow me to access the biz and blat attributes. Does anyone have any ideas how this might be done? Thanks.