admin管理员组文章数量:1295296
I'm trying to check one from radio buttons in radio list, but without luck.
Could somebody tell me what i'm doing wrong?
Thanks for any help.
I tried to do it by this way:
<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);
};
I'm trying to check one from radio buttons in radio list, but without luck.
Could somebody tell me what i'm doing wrong?
Thanks for any help.
I tried to do it by this way:
<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);
};
Share
edited Sep 25, 2014 at 13:29
George Smith
asked Sep 25, 2014 at 12:58
George SmithGeorge Smith
1432 gold badges3 silver badges15 bronze badges
4 Answers
Reset to default 2It seems that the value of data.clientSide is not in the list goalTypeList. Change the value to match any..
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);
};
The value in your $scope.data = { clientSide: 'ng' };
doesn't match any of the values in $scope.goalTypeList
.
If the clientSide value on $scope.data
was either dials, conversations, appointments or orders then the radio buttons should then load with one of the radio buttons selected.
I hope this helps.
Like @Marc Harry said your ng-value
should be equal ng-model
. To make it more dynamic (let's say you get an object from the backend and the selected value may change) you could do following:
<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>
.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: selectedValue()
};
function selectedValue = function() {
for(let i = 0; i < $scope.goalTypeList.length; i++) {
if ($scope.goalTypeList[i].selected) {
return $scope.goalTypeList[i].value;
}
}
};
you can use ion-select also with ionChange event:
<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>
In your typeScript:
checkValue(event){ console.log(event.detail.value)}
本文标签: javascriptIonicAngular unable to ionradio to be checked by defaultStack Overflow
版权声明:本文标题:javascript - Ionic + Angular unable to ion-radio to be checked by default - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741617436a2388607.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论