Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
cómo obtener valor del cuadro de texto usando mecanografiado en angular 2

Soy un principiante en angular2/mecanografiado. Estoy tratando de obtener números de dos cuadros de texto y agregar ambos números y mostrar el resultado mediante interpolación.

 @Component({ selector: 'my-app', template: `<h1>Hello {{name}}</h1> <h1>{{D}}</h1> <form> <p>first number:<input type="text" id="num1"></p> <p>second number:<input type ="text1" id="num2"></p> <h1> {{result}}</h1> </form> <test-app></test-app>` }) export class AppComponent { name = 'Angular'; value : number;value1 : number;result:number; constructor(value : number,value1 : number,result:number) { this.value = parseFloat ((document.getElementById("text") as HTMLInputElement).value); this.value1 = parseFloat((document.getElementById("text1") as HTMLInputElement).value); this.result=this.value+this.value1; }}
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

La forma más fácil es usar la variable de referencia de la plantilla:

 @Component({ selector: 'app-little-tour', template: ` <input #newHero > <button (click)="addHero(newHero.value)">Add</button> }) export class LittleTourComponent { addHero(newHero: string) { console.log(newHero) } }

Puede encontrar una guía completa para la entrada de usuario en Angular aquí: https://angular.io/guide/user-input

about 4 years ago · Santiago Trujillo Report

0

si obtiene sin usar ngModel:

 var num1= ((document.getElementById("num1") as HTMLInputElement).value); var num2= ((document.getElementById("num2") as HTMLInputElement).value); var result=parseInt(num1)+parseInt(num2); console.log(result);
about 4 years ago · Santiago Trujillo Report

0

HTML

 <p>first number:<input type="text" id="num1" [(ngModel)] = "value" ></p> <p>second number:<input type ="text1" id="num2" [(ngModel)] = "value1"></p> <h1> {{value + value1}}</h1>

Clase de componente

 export class AppComponent {}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!