Lucian Lucian - 19 days ago 6
AngularJS Question

Angular How to obtain onselect event

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

Answer

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

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

Because the ng-repeat 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 ng-options 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-option="x.data for x in myItems"> 
</select>

Then in our controller

$scope.SelectedRow = function(){
          //here take action or do whatever you want to. 
        }