2016-09-27 74 views
0

我似乎無法得到這個工作。離子電臺按鈕

這是我的HTML。

<input type="radio" ng-value="0" checked="{{value0}}"/> 
    <label>Standard</label> 

    <br> 

<input type="radio" ng-value="1" checked="{{value1}}"/> 
     <label>Hidden</label> 

這是我的js。我所做的就是調用一個端點。如果它返回0,那麼應該檢查標準。如果它返回1,則應檢查隱藏。

$http.get(www.website.com, {"headers": {authorization: strToken}}).success (function(response) 
    { 

     console.log (angular.toJson (response)) 


     if (response==0) 
     { 
      $scope.value0=true 
      console.log ('value is 0') 

     } 
     else if (response==1) 
     { 
      $scope.value1=true 
      $scope.value0=false 
      console.log ('value is 1') 

     } 


}) 

回答

0

請不要在JS如下:

$http.get(www.website.com, {"headers": {authorization: strToken}}).success (function(response) 
    { 
     $scope.app= {}; //Blank object to interact with DOM 
     $scope.app.value0 = false; 
     $scope.app.value1 = false; 
     console.log (angular.toJson (response)) 


     if (response==0) 
     { 
      $scope.app.value1=false; 
      $scope.app.value0=true; //put your value in object which we created 
      console.log ('value is 0') 

     } 
     else if (response==1) 
     { 
      $scope.app.value1=true; //put your value in object which we created 
      $scope.app.value0=false; //put your value in object which we created 
      console.log ('value is 1') 

     } 


}) 

,並在你的HTML:

<input type="radio" ng-value="0" checked="{{app.value0}}"/> 
    <label>Standard</label> 

    <br> 

<input type="radio" ng-value="1" checked="{{app.value1}}"/> 
     <label>Hidden</label> 

或者你可以用這樣也沒有括號:

<input type="radio" ng-value="0" checked="app.value0"/> 
    <label>Standard</label> 

    <br> 

<input type="radio" ng-value="1" checked="app.value1"/> 
     <label>Hidden</label> 

希望它會幫助你。

+0

謝謝你嘗試,但它不起作用。相反,它會選擇它們兩個。 – noor

+0

請檢查我更新的JS代碼並嘗試 – Naitik