Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular How to obtain onselect event

Tags:

angularjs

I am displaying some data in a smart-table component(using angular). The last column is a select element. What i want to do is plug-in to the "on-select" change event and do something with the data displayed in the row.

Here is my plunker :

What i want to achieve is displayed in the comment

like image 249
Lucian Avatar asked Dec 24 '22 04:12

Lucian


1 Answers

If you want to create a Dropdown list its better to use ng-options then ng-repeat.

<select ng-options="x.data for x in myItems"> 
</select>

Because the ngRepeat directive repeats a block of HTML code for each item in an array, it can be used to create options in a dropdown list, but the ngOptions directive was made especially for filling a dropdown list with options, and has at least one important advantage:

Dropdowns made with ng-options allows the selected value to be an object, while dropdowns made from ng-repeat has to be a string.

Add ng-change:

<select ng-change="SelectedRow()" ng-options="x.data for x in myItems"> 
</select>

Then in our controller:

$scope.SelectedRow = function(){
    //here take action or do whatever you want to. 
}
like image 139
Keyur Shah Avatar answered Jan 02 '23 19:01

Keyur Shah