是AngularJS的新手。经过长时间的努力,我找到了如何在Angularjs中使用Auto-complete。
现在,在选择自动完成的值时,根据所选值,需要填充其他字段。即。加载屏幕时,默认值将加载到文本框1和文本框2中。当用户通过文本框1中的auto-compelete选择新值时,必须填充Testbox 2中的相应值。
<table>
<tr>
<th>Project number</th>
<th>Project Name</th>
</tr>
<tr ng-repeat="s in projectListObj">
<td><input name="projects" type="text" placeholder="Project Number" ng-model="s.project_number" typeahead="s as s.project_number for s in projectData | filter:{project_number:$viewValue}" | limitTo:8" class="form-control"></td>
<td><input type="text" name="proj-name" placeholder="Project Name" ng-model="s.project_name"/></td>
</tr>
</table>
答案 0 :(得分:2)
您可以将手表放在你的ng型号上。 当您进行更改时,您将更新其他模型
$scope.$watch('BillDate1', function (newval, oldval) {
verfifyDate();
if (newval != undefined)
$scope.SearchModel.OtherVal[0] = newval;
if (newval == null)
$scope.SearchModel.OtherValTwo[0] = '';
});
更简洁的方法是使用模板
<input type="text" name="Person Contacted"
typeahead="a as a.Name for a in getCustomerContactDetails($viewValue)"
model="s.allCustomerContact.Name" typeahead-on-select='s.onSelectContactPerson(allCustomerContact.Name)' >
根据您的具体情况,我认为您想要的是将整体放在预先输入上:
<td><input type="text" name="proj-name" placeholder="Project Name" ng-model="s" uib-typeahead="r as r.project_name for r in projectData"/></td>
这样您就可以显示数字和名称,因为您在as语句中指定它。这是一个掠夺者
https://plnkr.co/edit/MzYHvdQvZ5LALI3Ge2av?p=preview
我已经使用了project_name,因为使用typeahead
似乎更清楚了希望有所帮助