===== Billentyű kiválasztása =====
onKeyUp(event:any) {
if(event.key == 'Enter') {
console.log('Az Enter lett lenyomva');
}
}
===== Háromszög =====
ng new app01
cd app01
code .
ng g c triangle
ng add bootstrap
//...
import { ReactiveFormsModule } from '@angular/forms';
//...
import: [
ReactiveFormsModule
]
//...
@import "bootstrap";
Háromszög területe
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-triangle',
templateUrl: './triangle.component.html',
styleUrls: ['./triangle.component.scss']
})
export class TriangleComponent implements OnInit {
base = new FormControl('');
height = new FormControl('');
area = new FormControl('');
areaVisible = false;
constructor() { }
ngOnInit(): void {
}
onKeyup(event:any) {
if (event.key == 'Enter') {
this.onKeyEnter();
}
}
onKeyEnter() {
let base = Number(this.base.value);
let height = Number(this.height.value);
let area = this.calcArea(base, height);
this.areaVisible = true;
this.area.setValue(area);
}
calcArea(base: number, height: number) {
return base * height / 2;
}
}
{{:oktatas:web:angular:triangle.png|}}