When the onchange()
event is triggered in the Select/Option element, it is supposed to write the value of the JSON file as an angular expression to the test ID div
.
However, it currently writes it as a string: {{names[1].thnev}}
(Manually inserting this into the ID div
works fine.)
I have been struggling with this for the past 4 hours. Can someone please help me figure out what I missed?
<div ng-app="myApp" ng-controller="customersCtrl">
<select id="thaz" name="thaz" class="selectbox" onchange="onChange(this.value)">
<option ng-repeat="x in names" value="{{x.id}}">{{x.id}} - {{x.thnev}}</option>
</select>
<div id="list"></div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("al_list_th.php")
.then(function (response) {$scope.names = response.data.records;});
});
function onChange(value) {
document.getElementById("list").innerHTML = "{{names[" + value + "].thnev}}";
}
</script>