Sorry if this is a basic question but I can't seem to figure it out.
Basically, I want to take an [(ngModel)]
input value from the template and then pass it along to my component. I feel like this is pretty basic Angular 2 stuff but I can't seem to get it.
My code:
input.html
:
<app-root>Loading...</app-root>
app/app.component.html
<input type="number" [(ngModel)]="value1">
<input type="number" [(ngModel)]="value2">
<!--I want my function value to update every time [(ngModel)] is updated
{{someFunction}}
app/app.component.ts
:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
someFunction(): number {
// I want to pass value1 and value 2 here from my ngModel in my template
return value1 * value2
}
}
You have to declare these variables in your component.
export class AppComponent {
value1: number;
value2: number;
someFunction() {
return this.value1 * this.value2;
}
}
Working plunker
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With