how to get value from textbox using typescript in angular 2 -
i beginner angular2 / typescript i'm trying numbers 2 textboxes , adding both numbers , display result using interpolation
@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") htmlinputelement).value); this.value1 = parsefloat((document.getelementbyid("text1") htmlinputelement).value); this.result=this.value+this.value1; }}
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>
component class
export class appcomponent {}
Comments
Post a Comment