2
Someone could help me, I’m starting to use Angular now, and I’m having a big confusion at the time of how to study...
Basically, when I click the button it does nothing... it is possible that the error is grotesque, but I am stuck
<input type="text" placeholder="Valor 1"
(input) = 'valor1'
/>
<input type="text" placeholder="Valor 2"
(input) = 'valor2'
/>
<button (click)="calcularSoma(valor1, valor2)" class="btn btn-primary">Calcular</button>
<p>
{{calcularSoma(valor1, valor2)}}
</p>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-calculator',
templateUrl: './calculator.component.html',
styleUrls: ['./calculator.component.css']
})
export class CalculatorComponent {
value1: number;
value2: number;
constructor() {
}
calcularSoma(value1: number, value2: number){
return this.value1 + this.value2;
}
}
Thank you! It was extreme, I’m not even a little accustomed to these 2 languages operating this way... If you don’t mind me asking? Why Property Binding or Event Binding wasn’t working?
– Ravel Sbrissa Okada
The Event Binding was not working because basically you were not picking up the input value. To work would have to do something like (input)="valor1 = $Event.target.value".
– LeAndrade