0

我想用angularjs ui-bootstrap.Got製作一個選項卡工作。angularjs引導ng-repeat不工作標籤內

在選項卡下方,使用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代碼:在plunker

var TabsDemoCtrl = function ($scope) { 
    $scope.tabs = [ 
    { title:'one', content:'Dynamic content 1' }, 
    { title:'two', content:'Dynamic content 2'} 
    ]; 

}; 

完整代碼:http://plnkr.co/edit/xDEP8W?p=preview

+1

這就是爲什麼我喜歡在控制器中初始化我計劃使用/需要的所有內容。 ** tabset創建自己的作用域,控制器無法訪問**。如果你把'$ scope.searchnotworking = {}; $ scope.searchworking = {};'在你的控制器中,它工作。這是因爲輸入的ng模型會在最接近的範圍(tabset)中查找並在該範圍上設置模型。只要你使用正確的東西來過濾('filter:searchnotworking.title') - 過濾器只有真正的工作 - http://plnkr.co/edit/ntJQRGsvXp5LtwbSi4zz?p=preview – Ian

回答

2

,如果你只需要添加$scope.searchnotworking = [];到JS它將初始化。不完全確定爲什麼它不會,否則,我想範圍。