Here is an example of an angular
array used in a select
tag:
var names= [{name: 'Superman', val: '1'}, {name: 'Batman', val: '2'}];
$scope.names =names;
$scope.FormData = {};
$scope.FormData.name = $scope.names[1];
In the above array, how can I select an item using its name
or val
rather than by index (1
):
$scope.FormData.name = $scope.names['2']; #will select the {name: 'Batman', val: '2'}
You can find more details about this topic in a question I posted on Stack Overflow here.