dailuwen 发表于 2015-9-28 15:30:32

ion-radio ng-value 值不能为string类型

ion-radio ng-value 值不能为string类型,话不多说直接附代码......
controller里面定义
$scope.onVehicleType = function(){
                        $scope.vehPopup = {'vehicleType':$scope.vehicle.vehicleType};
                        var vehicleType =$ionicPopup.show({
                                templateUrl: 'templates/popup/vehicleType.html', // String (可选)。在弹窗body内的html模板的URL : '<h3>这是弹框</h3>',
                                title : '选择车型',
                                scope : $scope,
                               
                                buttons : [
                                           {text : 'Cancel'},
                                           {text : '<b>Ok</b>',
                                                type : 'button-positivve',
                                                onTap : function(e){
                                                        if(null != $scope.vehPopup.vehicleType){
                                                                $scope.vehicle.vehicleType = $scope.vehPopup.vehicleType;
                                                        }
                                                       
                                                        // 当点击时,e.preventDefault() 会阻止弹窗关闭。
                                                        return $scope.vehPopup.vehicleType;//返回给定的值
                                                }
                                           }
                                  ]
                        });
                };以上是 自定义controller,一个方法,当触发这个方法的时候,弹出vehicleType.html 页面,
<div class="list">以下为执行结果!
会默认选择 车型4.5 选项,而且直接报错或拿不到值

dailuwen 发表于 2015-9-28 15:31:45

html页面好像没显示对,重新附上!

dailuwen 发表于 2015-9-28 15:32:02

<div class="list">
                <ion-radio ng-model="vehPopup.vehicleType" ng-value='4'>车型4</ion-radio>
                <ion-radio ng-model="vehPopup.vehicleType" ng-value='sss4.5'>车型4.5</ion-radio>
                <ion-radio ng-model="vehPopup.vehicleType" ng-value='5'>车型5</ion-radio>
</div>

dailuwen 发表于 2015-9-28 17:13:12

原因已找出。
直接这样写不行,会报错或取不到值,
<div class="list">
                <ion-radio ng-model="vehPopup.vehicleType" ng-value='4'>车型4</ion-radio>
                <ion-radio ng-model="vehPopup.vehicleType" ng-value='sss4.5'>车型4.5</ion-radio>
                <ion-radio ng-model="vehPopup.vehicleType" ng-value='5'>车型5</ion-radio>
</div>
如果这样写那就没任何问题了。
$scope.vehTypeList = [{'text':'车型4', 'value':'4.0'},{'text':'车型4', 'value':'sss4.5'},{'text':'车型4', 'value':'5.0'}];
                       

dailuwen 发表于 2015-9-28 17:13:48

dailuwen 发表于 2015-9-28 17:13
原因已找出。
直接这样写不行,会报错或取不到值,



<div class="list">
        <ion-radio ng-repeat="item in vehTypeList" ng-value="item.value" ng-model="vehPopup.vehicleType">
          {{ item.text }}
      </ion-radio>
</div>
页: [1]
查看完整版本: ion-radio ng-value 值不能为string类型