2016-07-18 93 views
0

我是新的角度,我想改變單選按鈕的顏色是它被選中,也想獲得該值。我嘗試了很多,但得到$範圍未定義。這裏是我的代碼HTML如何使用角度更改單選按鈕顏色?

<form action="" ng-controller="howSoonContr"> 
 
        <div class="form-group"> 
 
        <div data-toggle="buttons"> 
 
         <label class="btn btn-default btn-circle btn-lg active"><input type="radio" name="q1" value="0" ng-change="howSoonClick()" ng-model="time.min"><a>5 mins</a></label> 
 
         <label class="btn btn-default btn-circle btn-lg"><input type="radio" name="q2" value="1" ng-model="time.min"><a>10 mins</a></label> 
 
         <label class="btn btn-default btn-circle btn-lg"><input type="radio" name="q3" value="2" ng-model="time.min"><a>20 mins</a></label> 
 
         <label class="btn btn-default btn-circle btn-lg"><input type="radio" name="q4" value="3" ng-model="time.min"><a>30 mins</a></label> 
 
         <label class="btn btn-default btn-circle btn-lg"><input type="radio" name="q5" value="4" ng-model="time.min"><a>45 mins</a></label> 
 
        </div> 
 
        </div> 
 
       </form>

這是我JS

.controller("howSoonContr", function($scope) { 
 
    console.log("we are in howSoonContr"); 
 
    //console.log($scope.time); 
 
    //if ($scope.time) { 
 

 
     console.log("here is the hello " + $scope.time); 
 

 
     $scope.howSoonClick = function(time) { 
 
      console.log("here is the hello " + $scope.time); 
 
     } 
 

 
})

請幫助我。

回答

0

check this answer :它使用CSS整個類型複選框更改盒

的顏色和選擇
+0

謝謝你的建議,但ng模型的價值還沒有得到。 –

0

你必須使用time.min訪問的價值,它不是一個對象時,它是一個數組,可以用$ scope.time .min

要改變顏色,你必須添加$手錶它

+0

感謝您的回覆,我使用了$ scop.time.min,但仍然不確定。 –