2017-04-06 64 views
0

這裏進出口新的angularTypescript請幫助我如何綁定TextBoxData.Like 在這裏,我有兩個textBoxt和一個按鈕如何文本框的值打至梅索德使用AngularTypescript

<div> 
    <input type="text" class="form-control" id="txtx1" /> 
    <br /> 
    <input type="text" class="form-control" id="txtx" /> 
    <input type="button" class="btn btn-success" value="Submit" ng-click="GetData()" /> 
</div> 

這裏我怎樣才能綁定這兩個打字稿中的文本框值Like

public class Employeee(Employee ee) 
{ 
} 
+2

什麼是你想要的實際問題解決?爲什麼你想在TypeScript中做到這一點?通常視圖綁定是最好的方法。見https://angular.io/docs/ts/latest/guide/template-syntax.html –

+1

和ng-click是AngularJS ... – Alex

+0

請建議我如何綁定這兩個值像這裏我的目標是插入數據 –

回答

0

Angular不像Angular 1那樣工作。您需要更改很多以獲得此工作。我會建議你通過這個link。你可以試試下面的代碼

<div> 
     <input type="text" class="form-control" id="txtx1" [(ngModel)]="fname" /> 
     <br /> 
<input type="text" class="form-control" id="txtx" [(ngModel)]="lname" /> 
     <input type="button" class="btn btn-success" value="Submit" (click)="GetData()" /> 
    </div> 

public class Employeee(Employee ee) 
{ 
    GetData() { console.log(this.fname +','+ thislname); } 
    //you can assign this.fname = 'hello'; 
} 
+0

可能會提請代碼或任何網址 –

+0

我給你上面的鏈接。點擊它的更多細節如何使用表格 –

+0

你檢查上面的代碼? –

0

您可以創建一個角度分量這樣創建雙向綁定,使用打字稿

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'a-selector', 
    template: `<div> 
        <input type="text" class="form-control" id="txtx1" [(ngModel)]="text1"/> 
         <br /> 
        <input type="text" class="form-control" id="txtx" [(ngModel)]="text2"/> 
        <input type="button" class="btn btn-success" (click)="GetData()" /> 
       </div>` 
}) 
export class EmployeeComponent { 
    text1: string; 
    text2: string; 

    GetData(): void{ 

    } 
} 

問候

相關問題