Gary
Gary

Reputation: 1

Angular 2 data binding

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

Upvotes: 0

Views: 108

Answers (1)

user8094098
user8094098

Reputation:

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

Upvotes: 1

Related Questions