export class Triangle {
base: number;
height: number;
area: number;
constructor() {
this.base = 0;
this.height = 0;
this.area = 0;
}
calcArea() {
this.area = this.base * this.height / 2;
}
}
===== Használat =====
import { Component } from '@angular/core';
import { Triangle } from './triangle';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'triangle';
base: string;
height: string;
area: string;
constructor() {
this.base = '';
this.height = '';
this.area = '';
}
calcArea(): any {
let triangle = new Triangle();
triangle.base = Number(this.base);
triangle.height = Number(this.height);
triangle.calcArea();
this.area = String(triangle.area);
}
}
Template:
Háromszög
Háromszög területe
{{ title }} app is running!
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }