gpt4 book ai didi

javascript - ng-switch 不适用于 angular-ui typeahead

转载 作者:行者123 更新时间:2023-11-30 17:28:06 25 4
gpt4 key购买 nike

我正在使用 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 Controller :

var person_info =  [
{
"name": "Tom",
"id": "111"
},
{
"name": "Sam",
"id": "222"
},
{
"name": "James",
"id": "333"
}
];
$scope.person_info = person_info;

最佳答案

您可以使用 ng-if/ng-show/ng-hide 而不是 ng-switch

这里是一个带有 ng-if 的代码

 <div ng-if="selected.name == null" > 
<BR><BR>
</div>
<div ng-if="selected.name">
<pre>Person info: {{selected.name}} {{selected.id}}</pre>
</div>

只需将其替换为 ng-switch

关于javascript - ng-switch 不适用于 angular-ui typeahead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com