Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twitter bootstrap 角度+;ui.bootstrap.buttons+;无线电滤波器_Twitter Bootstrap_Angularjs_Filter_Radio - Fatal编程技术网

Twitter bootstrap 角度+;ui.bootstrap.buttons+;无线电滤波器

Twitter bootstrap 角度+;ui.bootstrap.buttons+;无线电滤波器,twitter-bootstrap,angularjs,filter,radio,Twitter Bootstrap,Angularjs,Filter,Radio,我想要一个按钮组充当单选按钮 我想要的是: 默认情况下应禁用按钮,但默认情况下应显示所有条目 单选按钮行为 如何使用当前代码实现这一点 我的HTML: Filter By Title: <div class="btn-group"> <button type="button" ng-repeat="title in titles" class="btn btn-default" ng-model="selected[title]" btn-checkbox>{{ti

我想要一个按钮组充当单选按钮

我想要的是:

  • 默认情况下应禁用按钮,但默认情况下应显示所有条目
  • 单选按钮行为
如何使用当前代码实现这一点

我的HTML:

Filter By Title: 
<div class="btn-group">
<button type="button" ng-repeat="title in titles" class="btn btn-default" ng-model="selected[title]" btn-checkbox>{{title}}</button>
</div>

<table class="table table-bordered table-striped">
      <thead>
        <tr>
          <th>Title</th>
          <th>Text</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="entry in entries | filter:byTitle">
          <td>{{entry.title}}</td>
          <td>{{entry.text}}</td>
        </tr>
      </tbody>
    </table>   

这和你想的一样吗

注意:您的按钮需要有
ng类
ng点击
。由于ng repeat创建子作用域,因此,
ng click需要是一个设置作用域变量的函数调用,而不是赋值

<button 
    type="button" 
    ng-repeat="title in titles" 
    class="btn btn-default" 
    ng-model="selected[title]" 
    btn-checkbox 
    ng-class="{active: title == selectedTitle}" 
    ng-click="setSelectedTitle(title)">{{title}}</button>
我不确定你是否想让它切换。如果没有:

$scope.setSelectedTitle = function (value) {
    $scope.selectedTitle = value;
};

这和你想的一样吗

注意:您的按钮需要有
ng类
ng点击
。由于ng repeat创建子作用域,因此,
ng click需要是一个设置作用域变量的函数调用,而不是赋值

<button 
    type="button" 
    ng-repeat="title in titles" 
    class="btn btn-default" 
    ng-model="selected[title]" 
    btn-checkbox 
    ng-class="{active: title == selectedTitle}" 
    ng-click="setSelectedTitle(title)">{{title}}</button>
我不确定你是否想让它切换。如果没有:

$scope.setSelectedTitle = function (value) {
    $scope.selectedTitle = value;
};

您将如何更改它以模拟真实的复选框行为(多选)?在我看来,这应该是一个新问题,因为您询问了单选按钮,而现在您想要它复选框。无论如何,要做到这一点,您需要三个布尔变量-每个按钮一个,只需使它使ng click切换该变量即可。然后它们将独立切换。您将如何更改它以模拟真实的复选框行为(多选)?在我看来,这应该是一个新问题,因为您询问了单选按钮,现在您需要它复选框。无论如何,要做到这一点,您需要三个布尔变量-每个按钮一个,只需使它使ng click切换该变量即可。然后它们将独立切换。