javascript - Ionic + Angular 默认无法勾选ion-radio

标签 javascript angularjs radio-button

我正在尝试从单选列表中的单选按钮中检查一个,但没有运气。

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

感谢您的帮助。

我试过这样做:

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

最佳答案

似乎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);
    };

关于javascript - Ionic + Angular 默认无法勾选ion-radio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26039271/

相关文章:

javascript - 如何使用 Angularjs 在加载时显示图像?

javascript - ng-href ="#/myanchor"不再像往常一样使用 angularjs 1.6.1

angularjs - CORS Node js问题

javascript - 单选按钮在 Vue.js 中无法正常工作

javascript - 使用 JavaScript 生成 PDF 文件

javascript - 在 javascript 中使用 Spring 变量

java - android webview.loadUrl 不会加载另一个网页

android - 在 Android 中使用 setError 检查 RadioGroup 空字段

c# - WinForm 绑定(bind)单选按钮

javascript - npm 多模块和主入口点