【发布时间】:2017-07-06 03:58:57
【问题描述】:
我是 Angular 2 的新手。我正在尝试从视图中的输入更新组件中的变量。不确定如何将我的输入绑定到变量?谢谢
【问题讨论】:
标签: angular data-binding components
我是 Angular 2 的新手。我正在尝试从视图中的输入更新组件中的变量。不确定如何将我的输入绑定到变量?谢谢
【问题讨论】:
标签: angular data-binding components
我认为最简单的方法是使用 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
【讨论】: