我正在使用 angular-ui typeahead 指令和 ng-switch。目的是在输入预输入框时,会出现以“人员信息”开头的行。否则,它不会出现。现在的问题是这一行总是出现。
我在这里创建了一个 plunker。 http://plnkr.co/edit/qEaYE6BHjmMewmlheFoh
相关代码段如下;HTML;
<div class='container-fluid' ng-controller="TypeaheadCtrl">
<h4>Static arrays</h4>
<!-- <pre>Model: {{selected }}</pre>
<pre>Model: {{selected.name}} {{selected.id}}</pre> -->
<div ng-switch="selected.name">
<div ng-switch-when="" >
<BR><BR>
</div>
<div ng-switch-default >
<pre>Person info: {{selected.name}} {{selected.id}}</pre>
</div>
</div>
<input type="text" ng-model="selected"
typeahead="person as person.name for person in person_info | filter:{name:$viewValue} | limitTo:8"
class="form-control">
</div>
Javascript控制器:
var person_info = [
{
"name": "Tom",
"id": "111"
},
{
"name": "Sam",
"id": "222"
},
{
"name": "James",
"id": "333"
}
];
$scope.person_info = person_info;