【发布时间】:2014-09-13 20:45:58
【问题描述】:
我正在尝试使用 angularjs ui-bootstrap 构建一个标签。让标签正常工作。
在标签下方,使用 ng-repeat 显示内容。 在其中一个选项卡中,想要搜索 ng-repeat 中列出的内容。 但搜索不起作用。
如果我将搜索框移出标签,它就可以工作。
HTML 代码:
<tabset>
<tab heading="Static title">Static content
Enter text to search
<input id="search" type="text" class="form-control" ng-model="search.title" placeholder="this is not working">
</tab>
<tab select="alertMe()">
<tab-heading>
<i class="glyphicon glyphicon-bell"></i> Alert!
</tab-heading>
I've got an HTML heading, and a select callback. Pretty cool!
</tab>
</tabset>
<input id="search" type="text" class="form-control" ng-model="search.title" placeholder="this is working">
<hr />
<div ng-repeat="tab in tabs | filter:search">
{{tab.content}}
</div>
占位符将帮助您找到有效的。
JS代码:
var TabsDemoCtrl = function ($scope) {
$scope.tabs = [
{ title:'one', content:'Dynamic content 1' },
{ title:'two', content:'Dynamic content 2'}
];
};
plunker 中的完整代码:http://plnkr.co/edit/xDEP8W?p=preview
【问题讨论】:
-
这就是为什么我喜欢初始化我计划使用/需要的控制器中的所有内容。 标签集创建自己的范围,控制器无权访问。如果你把
$scope.searchnotworking = {}; $scope.searchworking = {};放在你的控制器中,它就可以工作。这是因为输入的ng-model将在最近的范围(标签集)中查找并将模型设置在该范围内。并且过滤器只有在您使用正确的过滤器(filter:searchnotworking.title)-plnkr.co/edit/ntJQRGsvXp5LtwbSi4zz?p=preview 时才真正起作用
标签: javascript angularjs tabs angularjs-ng-repeat angular-ui-bootstrap