Problem when receiving a radio button value

Asked

Viewed 462 times

1

I’m starting to mess with Angularjs and I had a little trouble messing with radio Buttons. My HTML code:

<!DOCTYPE html>
<html>
<head>
<title>Temperature Converter</title>
<meta charset="UTF-8"/>
</head>
<body ng-app="temp-conv" ng-controller="converter">

<h1>Temperature Converter</h1>
    <h2>Temperatura de entrada</h2>
    <form>
        <input type="text" ng-model="valor"><br>
        <input type="radio" ng-model="ent" value="fahrenheit">Fahrenheit<br>
        <input type="radio" ng-model="ent" value="kelvin">Kelvin<br>
        <input type="radio" ng-model="ent" ng-value="celsius">Celsius<br>
        <input type="radio" ng-model="ent" value="rankine">Rankine<br>
        <input type="radio" ng-model="ent" value="reaumur">Réaumur<br>
        <br>
    <h2>Temperatura de saída</h2>
        <input type="radio" ng-model="sai" value="fahrenheit">Fahrenheit<br>
        <input type="radio" ng-model="sai" value="kelvin">Kelvin<br>
        <input type="radio" ng-model="sai" value="celsius">Celsius<br>
        <input type="radio" ng-model="sai" value="rankine">Rankine<br>
        <input type="radio" ng-model="sai" value="reaumur">Réaumur<br>
        {{ valor }}
    </form>


</body>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
<script src="script.js"></script>
</html>

And my Javascript:

var app = angular.module('temp-conv', []);

app.controller('converter', function($scope){
if ($scope.ent === "celsius") {
    $scope.valor = 3;
} else {
    $scope.valor = "4";
}
});

This Js is just a little test to see if the value is being passed, and it’s not working.

  • Welcome to Stackoverflow, provide more details of your problem so we can help you.

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.