【发布时间】:2014-10-17 18:55:52
【问题描述】:
我正在使用引导程序和角度来构建应用程序。在 HTML 页面中,我使用的是这个:
<div class="btn-group-justified" data-toggle="buttons-checkbox">
<button type="button" class="btn fzbtn-consServices" ng-repeat="service in availability.services">{{service.name}}</button>
</div>
它正在构建一个具有动态值的按钮组。有没有一种实用的方法来获取这个按钮组中的选定按钮?
我已经尝试了一些解决方案,其中一些正在工作,但我不知道这是否是最好的方法...
1:在“ng-click”方法中,我会将每个服务的属性值(例如“checked”属性)更改为 true 或 false;
2:我搜索了 btn-group 的任何 html 属性,它可以为我提供该组内所有选定的按钮,但我没有成功;
3:听说可以用Angular Filter解决这个问题,但是没找到类似的例子;
谁有更好的主意?非常感谢:)
这是迄今为止我找到的最佳解决方案:
<div class="btn-group-justified" data-toggle="buttons-checkbox">
<button type="button" class="btn fzbtn-consServices" ng-repeat="service in availability.services" ng-click="onClickService(service)" ng->{{service.name}}</button>
</div>
控制器:
$scope.onClickService = function (service) {
if (service.checked) {
service.checked = "false"
} else {
service.checked = "true";
}
}
【问题讨论】:
标签: angularjs twitter-bootstrap angularjs-filter buttongroup