2017-02-16 107 views
0

我是角2的新手。我試圖從我的視圖中的輸入更新組件中的變量。不知道如何將我的輸入綁定到變量?由於角2數據綁定

+0

這是我的看法: – Gary

+1

http://stackoverflow.com/questions/31623879/angular-2-two-way-binding-using-ng-model-is-not-working –

+1

https://angular.io/docs/ts/latest/cookbook/component-communication.html –

回答

1

我認爲最簡單的方法是使用ngModel

<input type="text" [(ngModel)]="yourVariable" /> 

然後在你的組件,你可以做一個變量「yourVariable」

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

@Component({ 
    selector: 'my-cool-app', 
    templateUrl: './something.html', 
    styleUrls: ['./something.css'] 
}) 
export class TimeSliderComponent { 
    private yourVariable: string; 

    constructor() { } 
} 

欲瞭解更多信息,請訪問: https://angular.io/docs/ts/latest/api/forms/index/NgModel-directive.html