私は以下のスニペットを作成しました。当分の間私はのためにとFahrenheitのためにランダムなmin
とmax
の値を追加しました。
var app = angular.module('app', []);
app.controller('test', function($scope) {
$scope.tempdata = {
"celsius": {
"min": 0,
"max": 100,
"value": 37
},
"fahrenheit": {
"min": 50,
"max": 150,
"value": 120
}
}
$scope.upDateData = function(data, type) {
$scope.obj.temp = data;
if (type == 'celsius') {
$scope.min = $scope.tempdata.celsius.min;
$scope.max = $scope.tempdata.celsius.max;
} else if (type == 'fahrenheit') {
$scope.min = $scope.tempdata.fahrenheit.min;
$scope.max = $scope.tempdata.fahrenheit.max;
}
}
});
.text-data {
width: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<div ng-app="app" ng-controller="test">
Number:
<input type="number" class="text-data" ng-model="obj.temp" min="{{min}}" max="{{max}}">
<div>
Celsius:
<input type="radio" ng-model="obj.selection" ng-value="tempdata.celsius.value" ng-change="upDateData(obj.selection, 'celsius')"> Fahrenheit:
<input type="radio" ng-model="obj.selection" ng-value="tempdata.fahrenheit.value" ng-change="upDateData(obj.selection, 'fahrenheit')">
</div>
</div>
あなたは[この](http://plnkr.co/edit/PUfnCyVsb3dlrRhuIUnL?p=preview)のようなものを持つことができませんか? – tanmay
残念ながら...私はapiにセルキウスとfarheneitを渡さなければなりません。それらのうちの1つはヌルで、もう1つは値を含みます。 –
私は単純なUIのものを好むと思うのですが(やりたいことのように)、APIを呼び出す直前にオブジェクトの変更をしています..あなたが尋ねたことは難しいですか、それはもっとクリーナーです反対に.. – tanmay