I'm new to angularjs and I really need help with this issue.
csApp.controller('expensesCtrl', function ($scope, $http) {
$scope.getExpenses = function () {
$http.post('/Home/ExpensesTableList').then(function (response) {
$scope.vendorList = response.data.csVendors;
$scope.list = response.data.csExpenses;
});
};
$scope.getExpenses();
});
// returned json
{"csExpenses":[{"vendorNo":1}],
"csVendors":[{"vendorNo":1,"vendorName":"Aliexpress"},{"vendorNo":2,"vendorName":"DHGate"}]}
<tr ng-repeat="item in list" ng-cloak >
<td>
<select ng-model="item.vendorNo"
ng-options="vendor.vendorName for vendor in vendorList track by vendor.vendorNo"></select>
</td>
</tr>
When I run this, it generates option value="?" and always selects the option value="?" I know option value="?" is generated when angular cannot find the right value from the list. But it does have a right value in the list which matches with the binding model value and type (integer).
<option selected="selected" value="?"></option>
<option value="1" label="Aliexpress">Aliexpress</option>
<option value="2" label="DHGate">DHGate</option></select>
Can someone please help why it is selecting the value="?" always?
ng-optionsis wrong, it is outputting the object and assigning it toitem.vendorNo; you probably just want it to output toitem.