Reputation: 77
I am trying to use check list where ng-model will bind the selected data based on two dynamic value. My code is:
<div ng-repeat="individualFieldInfo in formInatiatingData">
<div ng-repeat="individualListItem in individualFieldInfo.list"
<input type="checkbox" ng- model=
"userGivenData[individualFieldInfo.fieldName][individualListItem.value]">
{{individualListItem}}
</div>
</div>
Here,
userGivenData[individualFieldInfo.fieldName][individualListItem.value]"
is not workng. My JSON is:
$scope.userGivenData={
}
$scope.formInatiatingData = [
{
type:"checkList",
fieldName:"Fruit",
list : [
{
id:1,
value:"mango"
},
{
id:2,
value:"Banana"
},
{
id:3,
value:"Jackfruit"
}
]
}
]
For single dynamic binding userGivenData[individualFieldInfo.fieldName] is working. But, for two dynamicvalues, its not working. I am searching for a way where if a user check a checkbox, it will be binded in userGivenData.fieldName.value
Upvotes: 0
Views: 56
Reputation: 19748
angular.module('myApp', [])
.controller('MyController', function($scope){
$scope.someComplex = {
someInnerObj: {
thisIsAProperty: 'withSomeValue'
}
};
$scope.thing1 = 'someInnerObj';
$scope.thing2 = 'thisIsAProperty';
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyController">
<pre>{{someComplex|json}}</pre>
<pre>{{someComplex[thing1][thing2]}}</pre>
<input type="text" ng-model="someComplex[thing1][thing2]"/>
</div>
In a test case this does work... can you output some more of the data objects values you show there like I did in the sample here using the json filter and pre tags?
Upvotes: 2