Javascript 爱奥尼亚+;Angular无法默认选中离子无线电

Javascript 爱奥尼亚+;Angular无法默认选中离子无线电,javascript,angularjs,radio-button,Javascript,Angularjs,Radio Button,我正试着从单选列表中的单选按钮中选择一个,但运气不好 谁能告诉我我做错了什么 谢谢你的帮助 我试着这样做: <div class="list"> <ion-radio ng-repeat="item in goalTypeList" ng-value="item.value" ng-change="goalTypeChanged(item)" ng-checked

我正试着从单选列表中的单选按钮中选择一个,但运气不好

谁能告诉我我做错了什么

谢谢你的帮助

我试着这样做:

<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> 
.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);
        };

$scope.data={clientSide:'ng'}中的值
$scope.goalTypeList
中的任何值都不匹配

如果
$scope.data
上的客户端值为拨号、对话、约会或订单,则单选按钮应在选中其中一个单选按钮的情况下加载


我希望这会有所帮助。

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

html:


{{item.text}

js:

.controller('SettingsCtrl',函数($scope,$ionicLoading){
$scope.goalTypeList=[
{text:“Dials”,value:“Dials”,selected:true},
{文本:“对话”,值:“对话”,选中:false},
{文本:“约会”,值:“约会”,选中:false},
{文本:“订单”,值:“订单”,选中:false}
];
$scope.data={
客户端:“预约”
};
$scope.goalTypeChanged=函数(项){
log(“选定的目标类型,文本:,item.text,值:,item.value”);
};

如@Marc Harry所说,您的
ng值
应等于
ng模型
。要使其更具动态性(假设您从后端获得一个对象,并且所选值可能会更改),您可以执行以下操作:

<div class="list">

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

</div> 

{{item.text}

.controller('SettingsCtrl',函数($scope,$ionicLoading){
$scope.goalTypeList=[
{text:“Dials”,value:“Dials”,selected:true},
{文本:“对话”,值:“对话”,选中:false},
{文本:“约会”,值:“约会”,选中:false},
{文本:“订单”,值:“订单”,选中:false}
];
$scope.data={
客户端:selectedValue()
};
function selectedValue=函数(){
for(设i=0;i<$scope.goalTypeList.length;i++){
if($scope.goalTypeList[i].选中){
返回$scope.goalTypeList[i].value;
}
}
};

您也可以将离子选择与离子更改事件一起使用:

 <ion-select (ionChange)="checkValue($event)"  interface="popover" 
  placeholder="Select One" >
    <ion-select-option *ngFor="let item of userData" [value]="item"> 
   {{item.optionA}}</ion-select-option>
</ion-select>

谢谢,但我不知道如何传递到$scope.data中?请将$scope.data中的clientSide值设置为您想要的任何值,作为在单选按钮上选择的默认值。如果您不想在默认情况下选择任何值,请设置clientSide=''请使用英语作为答案,这会让您更容易理解。这感觉是排他性的,但StackOverflow是一个E仅限英语网站。请仅用英语回复,即使你的英语不是很好。人们可以随时编辑你的答案,以改进任何可能不清楚的地方。如果你对西班牙语网站感兴趣,这里有一个建议:
 <ion-select (ionChange)="checkValue($event)"  interface="popover" 
  placeholder="Select One" >
    <ion-select-option *ngFor="let item of userData" [value]="item"> 
   {{item.optionA}}</ion-select-option>
</ion-select>
checkValue(event){ console.log(event.detail.value)}