2016-11-15 5 views
0

私はregionで時計を持っていますが、ラジオボタンをクリックしても発砲していません。角度のラジオボタンが時計で点滅しない

何か間違っているのですか、ラジオボタンが角度を変えて一度だけ変化するのですか?とにかくフォームを使わずにこの周り?

<div class="filter-column"> 
    <div class="filter-title">Region</div> 
    <div class="bottom-line"></div> 
    <div class="overflow-container"> 
     <div ng-repeat="choice in regions| orderBy: 'description'"> 
     <input type="radio" 
      value="{{choice.name}}" 
      name="regionRadio" 
      ng-model="region"> 
     {{choice.description}} 
     </div> 
    </div> 
    </div> 

$scope.$watchCollection(watchRMDapisPopulate, 
    populateRMDfiltersView); 

    function watchRMDapisPopulate() { 
     return regionMarketDealerSrv.orgFilterData; 
     } 

     function populateRMDfiltersView(newValue, oldValue) { 
     if (newValue) { 
      $scope.regions = newValue.regions; 
     } 
     } 



     $scope.$watch('region', radioButtonRegion); 

     function radioButtonRegion(regionName) { 
     console.log(regionName) 
     if (regionName === 'All') { 
      regionMarketDealerSrv.populateRegions(); 
     } else { 
      regionMarketDealerSrv.populateMarkets(regionName); 
     } 
     } 
+1

は{{選択」= NG-値をする= "{{choice.name}}" の値を変更しよう.name}} " –

+0

はそれを' ng-value'に変更しましたが、まだ成功しませんでした。 'console.log(regionName)'は出力されません。 – dman

+1

関数をウォッチ式として使用するのはどうですか? $ scope(function(){return $ scope.region;}、radioButtonRegion) –

答えて

2

時計はng-model="region"を使用しているときにプリミティブ値を使用しているため、正しく変更を拾うことができません。値を変更すると、新しい参照が得られます。あなたは、あなたのモデルとして、オブジェクトのプロパティを使用して$watchことができます。

var app = angular.module('app', []) 
 

 
app.controller('MyController', function($scope) { 
 
    $scope.regions = [{ 
 
    name: 'a', 
 
    description: 'region A' 
 
    }, { 
 
    name: 'b', 
 
    description: 'region B' 
 
    }]; 
 

 
    $scope.selected = { 
 
    region: 'a' 
 
    }; 
 

 
    $scope.$watch('selected.region', radioButtonRegion); 
 

 
    function radioButtonRegion(newVal, oldVal) { 
 
    if (newVal !== oldVal) { 
 
     console.log(newVal, oldVal) 
 
    } 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="app" ng-controller="MyController"> 
 
    <div>Region</div> 
 
    <div ng-repeat="choice in regions| orderBy: 'description'"> 
 
    <input type="radio" value="{{choice.name}}" name="regionRadio" ng-model="selected.region">{{choice.description}} 
 
    </div> 
 
</div>

+0

ああ....私はそれを使用していましたが、私はそのようなデフォルトのチェック値を設定する方法がありません。私はng-checkedを使用することができないので、デフォルトのチェック値を作る方法に関するアイデアはありますか? – dman

+1

'$ scope.selected'オブジェクトに初期値を設定することができます。 – DTing

関連する問題