我有一个用于创建新作业的模态。有一个预先输入来搜索相关的客户。当我从该列表中选择一个客户时,我需要填充输入字段的属性。我做了一个plunkr,但我不能让typeahead工作。 plunkr
<input type="text" class="form-control" ng-model="CustomerName"
typeahead="job.Customers[0].CustomerName for job in jobArray | filter:$viewValue"
placeholder="Enter Customer" typeahead-on-select="selectedCustomer = $item;">
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">C. Name</span>
<input type="text" class="form-control" ng-model="CustomerName"
typeahead="job.Customers[0].CustomerName for job in jobArray | filter:$viewValue"
placeholder="Enter Customer" typeahead-on-select="selectedCustomer = $item;">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon">C. Address</span>
<input ng-model="CustomerAddress" class="form-control" type="text">
</div>
</div>
答案 0 :(得分:1)
您错过了ng-app="testApp"
声明。
typeahead
属性应如下所示:
typeahead="customer.customerName for customer in customers | filter:$viewValue"
不确定您希望通过job.Customers[0].CustomerName for job in customers
实现目标。
最后我只能猜测,但我认为您无法通过预先输入和输入下方输入客户数据吗?如果是这种情况,您应该将typeahead-on-select
更改为
typeahead-on-select="selectCustomer($item)"
并在控制器中添加selectCustomer
:
$scope.selectCustomer = function(customer){
$scope.customerName = customer.customerName;
$scope.customerAddress = customer.customerAddress;
};
查看更新的plunker。