I calculate with $ scope

0

Best regards to all, I have the following problem, I am trying to base myself on a code that works correctly, which is as follows:

<!DOCTYPE html>
<html>
<head>
	<title> mi aplicacion </title>
</head>
<body>
	<div ng-app="miAplication" ng-controller="miControlador">
		<p>Nombre de empleado:<input type="text" ng-model="empleado.nombreEmp"></p>
		<p>Horas trabajadas:<input type="number" ng-model="empleado.horasTrab"></p>
		<p>Cuota por hora: <input type="number" ng-model="empleado.cuotaHora"></p>
		<p>El sueldo de {{empleado.nombreEmp}} es de {{obtenerSueldo()}} </p>
	</div>
	<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
	<script>
		var app =angular.module('miAplication',[]);
		app.controller('miControlador',function($scope){
			$scope.empleado={
				nombreEmp:"Luis Camilo Jimenez",
				horasTrab:45,
				cuotaHora:10000,
				sueldo:0
			}
			$scope.calcularSueldo=function(){
				$scope.empleado.sueldo=$scope.empleado.horasTrab*$scope.empleado.cuotaHora;
			}
			$scope.obtenerSueldo=function(){
				$scope.calcularSueldo();
				return $scope.empleado.sueldo;
			}
		});
	</script>
</body>
</html>

Now in my code when trying to do the operation of the multiplication in the $ scope does not show me anything and also does not show me the suggested values.

<!DOCTYPE html>
<html>
<head>
	<title> Guia 2. actividad 2.2.</title>
	<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    	<style>
        table, th , td  {
          border: 1px solid grey;
          border-collapse: collapse;
          padding: 5px;
        }
        table tr:nth-child(odd) {
          background-color: #f1f1f1;
        }
        table tr:nth-child(even) {
          background-color: #ffffff;
        }
    	</style>
</head>
<body>
	<div ng-app= "convertirGradosC" ng-app = "micontrolador">
		<p>Ingrese GradosC fahrenheit inicial:<input type="number" ng-model="GradosC.Inicialf"></p>
		<p>Ingrese GradosC fahrenheit final:<input type="number" ng-model="GradosC.Finalf"></p>
		<p>{{GradosC.Inicialf}} °F son {{obtenerCelcius()}} °C</p>
		<p>{{obtenerCelcius()}}</p>

		<table>
  			<thead>
     			<td><b> GradosC Fahrenheit </b></td><td><b> GradosC Celcius </b></td>
  			</thead>
 			 <tr>
    		<td>{{GradosC.Inicialf}}</td>
   			 <td>{{GradosC.Finalf}}</td>
  			</tr>
		</table>
	</div>
	
	<script src="http://ajax.googleapis.com/ajax/libs/angularjs/2.0/angular.min.js"></script>
	<script>
		var app =angular.module('convertirGradosC',[]);
		app.controller('micontrolador',function($scope){
			$scope.GradosC={
				Inicialf:10,
				Finalf:20,
				Celcius:0
			}
			$scope.calcularCelcius=function(){
				$scope.GradosC.Celcius=($scope.GradosC.Inicialf-32)*(5/9);
			}
			$scope.obtenerCelcius=function(){
				$scope.calcularCelcius();
				return $scope.GradosC.Celcius;
			}
		});
	</script>
</body>
</html>

Note.What comes out as a table I put it to verify that if I show another different value.

Thank you very much.

    
asked by Daniel Mauricio Crdenas Forero 21.10.2017 в 07:04
source

2 answers

0

I found the biggest mistake for which I did not calculate what I needed.

is on the next line.

<div ng-app= "convertirGradosC" ng-app = "micontrolador">

The problem was that I was not calling the directive Controller if not ng-app .

Thanks to all, when the code ends I will post it as an answer.

    
answered by 22.10.2017 в 03:05
0

I was able to finish my code that allows reading the initial value and the final value in degrees Fahrenheit; and print a table with degrees in degrees Celsius, from the initial value to the final value of 1 in 1.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<head>
	<title> Guia 2. actividad 2.2.</title>
   	<style>
        table, th , td  {
          border: 1px solid grey;
          border-collapse: collapse;
          padding: 5px;
        }
        table tr:nth-child(odd) {
          background-color: #f1f1f1;
        }
        table tr:nth-child(even) {
          background-color: #ffffff;
        }
    	</style>
</head>
<body>
	<div ng-app= "convertircentigrados" ng-controller = "micontrolador">
		<p>Ingrese Grados fahrenheit inicial:<input type="number" ng-model="centigrados.inicialf"></p>
		<p>Ingrese Grados fahrenheit final:<input type="number" ng-model="centigrados.finalf"></p>

		<h2>Tabla de equivalencias entre Grados Fahrenheit y Grados Centigrados</h2>

		<table>
  			<thead>
  				<th><b>Index</b></th>
  				<th><b>Grados Fahrenheit</b></th>
     			<th><b>Grados Celcius</b></th>
  			</thead>
  			<tbody>
  				<tr ng-repeat= "i in range | limitTo:(centigrados.finalf-centigrados.inicialf+1)+i">
	 			  	<td>{{$index}}</td>
	    			<td>{{centigrados.inicialf++i}}</td>
	   				<td>{{(centigrados.inicialf+i-32)*(5/9)|number: 1}}</td>
   				</tr>
   			</tbody>
  		</table>
	</div>
	
	<script>
		var app =angular.module('convertircentigrados',[]);
		//controlador
		app.controller('micontrolador',function($scope,){
			$scope.centigrados={
				inicialf:0,
				finalf:100,
			}
			var range=[];
			for (var i = $scope.centigrados.inicialf; i < $scope.centigrados.finalf; i++) {
				range.push(i)
			}
			$scope.range= range;
		});
	</script>
</body>
</html>

I hope it helps.

    
answered by 22.10.2017 в 19:23