I am currently using a <datalist> for easy lookup. Each <option> in my datalist has a data-sysid attribute which acts as the actual value I need. Currently, I am using ng-model to set the id variable. However, by default, ng-model uses the value attribute. Is there any way to make ng-model use the value set in my data-sysid attribute instead of the value?
Here is what I currently have:
angular.module('myApp', [])
.controller('myController', function($scope) {
$scope.id = "";
});
angular.element(document).ready(() => {angular.bootstrap(document, ['myApp']);});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-controller="myController">
<input list="items" id="item-choice" name="item-choice"
placeholder="Choose an item" ng-model="id" />
<datalist id="items">
<option value="Item1" data-sysid="xyz">
<option value="Item2" data-sysid="abc">
<option value="Item3" data-sysid="123">
</datalist>
{{ id }}
<!-- I would like this to display data-sysid value instead -->
</div>
My desired behaviour would be like so:
- if I was to select
"Item1"the display (id) would bexyz - if I was to select
"Item2"the display (id) would beabc - if I was to select
"Item3"the display (id) would be123
Is there any way to achieve this using angularjs (preferably without jQuery)?
data-*attribute from the selected value, not how to model thevalueattribute.