2014-09-25 37 views
4

我试图从收音机列表中的单选按钮中选中一个,但没有运气。Ionic + Angular无法默认检查离子收音机

有人能告诉我我做错了什么吗?

感谢您的任何帮助。

我试图通过这种方式来做到这一点:

<div class="list"> 

     <ion-radio ng-repeat="item in goalTypeList" 
       ng-value="item.value" 
       ng-change="goalTypeChanged(item)" 
       ng-checked="item.selected" 
       ng-model="data.clientSide"> 
      {{ item.text }} 
     </ion-radio> 

    </div> 

JS:

.controller('SettingsCtrl', function($scope, $ionicLoading) { 

     $scope.goalTypeList = [ 
      { text: "Dials", value: "dials", selected: true }, 
      { text: "Conversations", value: "conversations" , selected: false }, 
      { text: "Appointments", value: "appointments" , selected: false }, 
      { text: "Orders", value: "orders", selected: false } 
     ]; 

     $scope.data = { 
      clientSide: 'ng' 
     }; 

     $scope.goalTypeChanged = function(item) { 
      console.log("Selected goalType, text:", item.text, "value:", item.value); 
     }; 

回答

1

值在$scope.data = { clientSide: 'ng' };不匹配$scope.goalTypeList任何值。

如果$scope.data上的clientSide值是dials,conversations,appointments或orders,那么单选按钮应该加载一个选中的单选按钮。

我希望这会有所帮助。

+0

谢谢,但我不知道怎么传递到$ scope.data? – 2014-09-25 14:14:43

+0

将$ scope.data中的clientSide值设置为无论您想要作为单选按钮上选定的默认值。如果你不想在默认情况下选择任何设置clientSide ='' – 2014-09-25 14:55:38

2

似乎data.clientSide的值不在列表goalTypeList中。改变以匹配任何值..

HTML:

<div class="list"> 

    <ion-radio ng-repeat="item in goalTypeList" 
      ng-value="item.value" 
      ng-change="goalTypeChanged(item)" 
      ng-checked="item.selected" 
      ng-model="data.clientSide"> 
     {{ item.text }} 
    </ion-radio> 

JS:

.controller('SettingsCtrl', function($scope, $ionicLoading) { 

    $scope.goalTypeList = [ 
     { text: "Dials", value: "dials", selected: true }, 
     { text: "Conversations", value: "conversations" , selected: false }, 
     { text: "Appointments", value: "appointments" , selected: false }, 
     { text: "Orders", value: "orders", selected: false } 
    ]; 

    $scope.data = { 
     clientSide: 'appointments' 
    }; 

    $scope.goalTypeChanged = function(item) { 
     console.log("Selected goalType, text:", item.text, "value:", item.value); 
    }; 
+0

请使用英语获得答案,这使得它更容易理解。 – EWit 2014-12-17 20:29:09

+0

它感觉独一无二,但StackOverflow是一个只有英文的网站。即使您的英语不是很好,也只能用英语回答。人们总是可以编辑你的答案来改善任何可能不清楚的事情。如果你对西班牙语的StackOverflow感兴趣,这里有一个提议:http://area51.stackexchange.com/proposals/42810/stack-overflow-in-spanish – 2014-12-17 21:04:41