I have dropdown inside my view that is being populated from factory(AJAX) API in other words I have a JSON formatted data to populate the dropdown(id,display_text) as follows:
My View
<select class="form-control padding-7" ng-model="selConnData.repeatSelect" ng-options="types.id as types.text for types in selConnData.connList" ng-change="updateConType('{{types.val}}')">
</select>
My Controller
$scope.selConnData = {
repeatSelect: null
};
getConnectionList.connectionList().then(function(response){
console.log(JSON.stringify(response.data));
var tempConnections = {};
var tempConnList = [];
angular.forEach(response.data.result, function(value, key) {
tempConnList.push({
id: value.Id,
text: value.Name,
val: "thrLoc"
});
});
$scope.selConnData.connList = tempConnList;
});
My Factory
app.factory('getConnectionList', function($http) {
var resultant = {};
resultant.connectionList = function(){
return $http({
method: 'GET',
url: "xyz"
});
}
return resultant;
});
My Final JSON o/p will be in:
[{
id: 1,
text: "Connection 1",
val: "8010"
},{
id: 2,
text: "Connection 3",
val: "8030"
},{
id: 9,
text: "Connection 4",
val: "8040"
}]
Now, my dropdown option will be like
<select>
<option value="1">Connection 1</option>
<option value="2">Connection 3</option>
<option value="9">Connection 4</option>
</select>
Up to here,everything is working, my ng-model gives me selected value,but i need a condition to run where on change of options I will check if(8010) do-something elseif(8030) do-something elseif(8040) do-something.
P.S: I tried ng-attr but not a best case(couldn't get the values out)