<bdo id='VgxJV'></bdo><ul id='VgxJV'></ul>
    <legend id='VgxJV'><style id='VgxJV'><dir id='VgxJV'><q id='VgxJV'></q></dir></style></legend>

    <i id='VgxJV'><tr id='VgxJV'><dt id='VgxJV'><q id='VgxJV'><span id='VgxJV'><b id='VgxJV'><form id='VgxJV'><ins id='VgxJV'></ins><ul id='VgxJV'></ul><sub id='VgxJV'></sub></form><legend id='VgxJV'></legend><bdo id='VgxJV'><pre id='VgxJV'><center id='VgxJV'></center></pre></bdo></b><th id='VgxJV'></th></span></q></dt></tr></i><div id='VgxJV'><tfoot id='VgxJV'></tfoot><dl id='VgxJV'><fieldset id='VgxJV'></fieldset></dl></div>
  1. <tfoot id='VgxJV'></tfoot>
  2. <small id='VgxJV'></small><noframes id='VgxJV'>

    1. AngularJS - 用作单选按钮的 3 按钮组

      时间:2023-10-21
      <tfoot id='SIyuj'></tfoot>

      <small id='SIyuj'></small><noframes id='SIyuj'>

        <bdo id='SIyuj'></bdo><ul id='SIyuj'></ul>

          <tbody id='SIyuj'></tbody>

            <i id='SIyuj'><tr id='SIyuj'><dt id='SIyuj'><q id='SIyuj'><span id='SIyuj'><b id='SIyuj'><form id='SIyuj'><ins id='SIyuj'></ins><ul id='SIyuj'></ul><sub id='SIyuj'></sub></form><legend id='SIyuj'></legend><bdo id='SIyuj'><pre id='SIyuj'><center id='SIyuj'></center></pre></bdo></b><th id='SIyuj'></th></span></q></dt></tr></i><div id='SIyuj'><tfoot id='SIyuj'></tfoot><dl id='SIyuj'><fieldset id='SIyuj'></fieldset></dl></div>
            1. <legend id='SIyuj'><style id='SIyuj'><dir id='SIyuj'><q id='SIyuj'></q></dir></style></legend>
              • 本文介绍了AngularJS - 用作单选按钮的 3 按钮组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                Using the Ionic framework, I'm trying to create a group of three buttons that act as radio buttons:

                If I click on Breakfast, I would like Lunch and Dinner to return to their normal (white) state, and Breakfast to turn Blue.

                With my current code, I can't get this functionality to work, although I can get the buttons to switch color, slightly randomly (perhaps I just don't understand the ng-class directive).

                Here is my HTML code:

                <div class="bar bar-subheader">
                 <div class="button-bar">
                   <a class="button" ng-class="{'button-positive' : !isActiveB, 'none': isActiveB}" ng-click="active('breakfast')">Breakfast</a>
                   <a class="button" ng-class="{'button-positive' : !isActiveL, 'none': isActiveL}" ng-click="active('lunch')">Lunch</a>
                   <a class="button" ng-class="{'button-positive' : !isActiveD, 'none': isActiveD}" ng-click="active('dinner')">Dinner</a>
                 </div>
                </div>
                

                My JS:

                $scope.active = function(meal) {
                
                 switch (meal) {
                   case 'breakfast':
                     $scope.$broadcast('slideBox.setSlide', 0);
                     $scope.isActiveB = $scope.isActiveB;
                     $scope.isActiveL = !$scope.isActiveL;
                     $scope.isActiveD = !$scope.isActiveD;
                     break;
                   case 'lunch':
                     $scope.$broadcast('slideBox.setSlide', 1);
                     $scope.isActiveB = !$scope.isActiveB;
                     $scope.isActiveL = $scope.isActiveL;
                     $scope.isActiveD = !$scope.isActiveD;
                     break;
                   case 'dinner':
                     $scope.$broadcast('slideBox.setSlide', 2);
                     $scope.isActiveB = !$scope.isActiveB;
                     $scope.isActiveL = !$scope.isActiveL;
                     $scope.isActiveD = $scope.isActiveD;
                     break;
                 }
                };
                

                I can put the code in JSFidle if you require more information and a working solution.

                Thanks for your help.


                NOTE: I would like to maintain my active() function, and use the ng-class directive if possible, as I have a lot of other code dependent on this function.

                解决方案

                Maybe this simplified example will help you a little:

                angular.module('plunker', []).controller('MainCtrl', function($scope) {
                    $scope.active = 'breakfast';
                    $scope.setActive = function(type) {
                        $scope.active = type;
                    };
                    $scope.isActive = function(type) {
                        return type === $scope.active;
                    };
                });

                <link rel="stylesheet" href="http://code.ionicframework.com/0.9.26/css/ionic.min.css">
                <script src="http://code.angularjs.org/1.2.13/angular.js"></script>
                
                <div ng-app="plunker" ng-controller="MainCtrl" class="bar bar-subheader">
                    <div class="button-bar">
                        <a class="button" ng-class="{'button-positive': isActive('breakfast')}" ng-click="setActive('breakfast')">Breakfast</a>
                        <a class="button" ng-class="{'button-positive': isActive('lunch')}" ng-click="setActive('lunch')">Lunch</a>
                        <a class="button" ng-class="{'button-positive': isActive('dinner')}" ng-click="setActive('dinner')">Dinner</a>
                    </div>
                </div>

                Demo: http://plnkr.co/edit/9HmuTStz70x5KoAvLaP4?p=preview

                这篇关于AngularJS - 用作单选按钮的 3 按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:你如何使单选按钮文本也可点击? 下一篇:使用 ng-repeat 时默认选中单选按钮

                相关文章

              • <legend id='w664y'><style id='w664y'><dir id='w664y'><q id='w664y'></q></dir></style></legend>

                  <i id='w664y'><tr id='w664y'><dt id='w664y'><q id='w664y'><span id='w664y'><b id='w664y'><form id='w664y'><ins id='w664y'></ins><ul id='w664y'></ul><sub id='w664y'></sub></form><legend id='w664y'></legend><bdo id='w664y'><pre id='w664y'><center id='w664y'></center></pre></bdo></b><th id='w664y'></th></span></q></dt></tr></i><div id='w664y'><tfoot id='w664y'></tfoot><dl id='w664y'><fieldset id='w664y'></fieldset></dl></div>
                  • <bdo id='w664y'></bdo><ul id='w664y'></ul>

                  1. <small id='w664y'></small><noframes id='w664y'>

                  2. <tfoot id='w664y'></tfoot>