Get full array with AngularJS

0

Template

<input type="text" data-ng-model="item.title" list="comicstitle">
  <datalist id="comicstitle">
    <option  data-ng-repeat="ttl in titles" value="{{ttl.name}}">
  </datalist>

js

$rootScope.titles = [{"id":"1","name":"Alface","value":"1.00"},{"id":"3","name":"Bacon","value":"2.00"},{"id":"4","name":"Queijo Cheedar","value":"2.00"},{"id":"5","name":"Mostarda Dijon","value":"2.00"}];

I need to fetch the item by filling a input with the array data

<input type="text" ng-model="name">
<input type="text" ng-model="id">
<input type="text" ng-model="value">
    
asked by anonymous 06.11.2014 / 01:01

1 answer

1

Just do it as follows

HTML

<div ng-controller="myCtrl">
    <input type="text" ng-model="item.title" list="comicstitle" />
    <select id="comicstitle" ng-model="item.titles">
        <option  value="{{$index}}" ng-repeat="ttl in titles"> {{ttl.name}} </option>
    </select>

    <input type="text" ng-model="titles[item.titles].name" />
    <input type="text" ng-model="titles[item.titles].id" />
    <input type="text" ng-model="titles[item.titles].value" />
</div>

Implement your solution.

DEMO JSFIDDLE

    
06.11.2014 / 11:36