Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass two values to ng-change function from ng-repeat

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!

like image 739
Syed Rasheed Avatar asked Mar 15 '23 06:03

Syed Rasheed


1 Answers

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)
}
like image 196
New Dev Avatar answered Mar 24 '23 23:03

New Dev