1
Reply

First Radio button should got selected of every radio group

Rashidul Islam

Rashidul Islam

Jan 30 2017 4:34 AM
243
/*My need is::

Case::

If I type "bx" in the input box:: group 1:: First radio button got selected and "is selected" set to true and others to false and if I remove the filter than it should set to the old data(i.e "Bus Array"). **group 2:same as group 1*/     Please reply asap if you have any solution. Link: https://jsfiddle.net/irashidul99/u888gg5t/1/

  1. <div ng-app="app" >  
  2.     <div ng-controller="ctrl">  
  3.       
  4. Type(Bx/ Nx / Ax): <input type="text" ng-model="checkPrice">  
  5.         <div ng-repeat="buses in BusArray">  
  6.         <span>group{{$index+1}}</span>  
  7.         <form>  
  8.       <div ng-repeat="bus in dd=(buses|filter:checkPrice)">  
  9.     <label style="font-size:12px; background-color:green; padding:2px;">  
  10.                 <input name="{{$parent}}" id="{{$parent.$index}}{{$index}}" type="radio" ng-checked="bus.IsSelected" ng-click="setSelected(buses,bus)" />  
  11.                 {{bus|json}}  
  12.                </label>  
  13.            
  14.             </div>  
  15.               </form>  
  16.             <div>  
  17.         </div>  
  18.           
  19.         <hr/>  
  20.        
  21.     </div>  
  22.        {{BusArray | json}}  
  23. </div>  
  1. //  
  2. var ngApp = angular.module('app', []);  
  3.    
  4. ngApp.controller('ctrl',function($scope){  
  5.   
  6. $scope.setSelected = function ($data, $pData) {  
  7.         angular.forEach($data, function (cu) {  
  8.                 cu.IsSelected = false;   
  9.         });  
  10.       $pData.IsSelected = true;   
  11.     };  
  12.     $scope.BusArray = [  
  13.     [{  
  14.   
  15.         "BusName""Ax. Travels",  
  16.         "Origin""DEL",  
  17.         "Destination""JAI",  
  18.         "TotalFare": 1200,  
  19.         "IsSelected"true  
  20.     }, {  
  21.   
  22.         "BusName""Bx. Travels",  
  23.         "Origin""DEL",  
  24.         "Destination""JAI",  
  25.         "TotalFare": 1600,  
  26.         "IsSelected"false  
  27.     }, {  
  28.   
  29.         "BusName""Bx. Travels",  
  30.         "Origin""DEL",  
  31.         "Destination""JAI",  
  32.         "TotalFare": 800,  
  33.         "IsSelected"false  
  34.     }, {  
  35.   
  36.         "BusName""Nx. Travels",  
  37.         "Origin""DEL",  
  38.         "Destination""JAI",  
  39.         "TotalFare": 400,  
  40.         "IsSelected"false  
  41.     }],  
  42.     [{  
  43.   
  44.         "BusName""Ax. Travels",  
  45.         "Origin""DEL",  
  46.         "Destination""JAI",  
  47.         "TotalFare": 1100,  
  48.         "IsSelected"true  
  49.     }, {  
  50.   
  51.         "BusName""Nx. Travels",  
  52.         "Origin""DEL",  
  53.         "Destination""JAI",  
  54.         "TotalFare": 1400,  
  55.         "IsSelected"false  
  56.     }, {  
  57.   
  58.         "BusName""Nx. Travels",  
  59.         "Origin""DEL",  
  60.         "Destination""JAI",  
  61.         "TotalFare": 600,  
  62.         "IsSelected"false  
  63.     }, {  
  64.   
  65.         "BusName""Bx. Travels",  
  66.         "Origin""DEL",  
  67.         "Destination""JAI",  
  68.         "TotalFare": 500,  
  69.         "IsSelected"false  
  70.     }]  
  71. ];  
  72.       
  73.      
  74. });  
 

Answers (1)