This is my html code
<select ng-model="node.field.name"
data-nodrag
ng-options="value.label as value.label group by value.name for value in myOptions"
ng-change="getConditionsByType(node.field.name,value.name)">
</select>
When is use getConditionsByType(node.field.name,value.name)
i am getting value.name as undefined
how can i access the values from ng-repeat when changing the options!
value
is not defined in the scope of ng-change
- it is only defined in the microsyntax expression of ng-options
.
Instead, make the model to be the "value" - i.e. the item of myObjects
.
<select ng-model="selectedOption"
ng-options="value as value.label group by value.name for value in myOptions"
ng-change="onChange()">
</select>
This means that you can't set node.field.name
to "value.name" directly - do so, in ngChange
instead:
$scope.onChange = function(){
$scope.node.field.name = selectedOption.name;
getConditionsByType($scope.node.field.name, selectedOption.name)
}
I think you want this..
<select ng-model="node.field"
data-nodrag
ng-options="value as value.label group by value.name for value in myOptions"
ng-change="getConditionsByType(node.field.name, node.field.label)">
</select>
This is not setting only the name
property of node.field
but the entire node.field
. Then you you can reference both node.field.name
and node.field.label
.
If I misunderstood and value
and node.field
don't have the same properties then use an intermediary field on scope to hold the value, watch that, and transform it to what you need to put in node.field
(or do the transformation inside ng-change
).
Check this one: http://plnkr.co/edit/RRWSYmEfCZu8aOrtNctl?p=preview
Main change
<select style="width: 100px;" ng-model="node.field.name" ng-change=temp()
ng-options="value.name as value.label group by value.name for value in myOptions"></select>