I am new to angular 2. I am trying to update a variable in my component from an input in my view. Not sure how to bind my input to the variable? Thanks
-
1stackoverflow.com/questions/31623879/…jeff carey– jeff carey2017-02-16 20:50:43 +00:00Commented Feb 16, 2017 at 20:50
-
1angular.io/docs/ts/latest/cookbook/component-communication.htmlGünter Zöchbauer– Günter Zöchbauer2017-02-16 21:11:09 +00:00Commented Feb 16, 2017 at 21:11
Add a comment
|
1 Answer
I think the easiest way is to use ngModel
<input type="text" [(ngModel)]="yourVariable" />
Then in your component, you can make a the variable "yourVariable"
import { Component } from '@angular/core';
@Component({
selector: 'my-cool-app',
templateUrl: './something.html',
styleUrls: ['./something.css']
})
export class TimeSliderComponent {
private yourVariable: string;
constructor() { }
}
For more info, check out: https://angular.io/docs/ts/latest/api/forms/index/NgModel-directive.html