【问题标题】:Angular 2 data bindingAngular 2 数据绑定
【发布时间】:2017-07-06 03:58:57
【问题描述】:

我是 Angular 2 的新手。我正在尝试从视图中的输入更新组件中的变量。不确定如何将我的输入绑定到变量?谢谢

【问题讨论】:

标签: angular data-binding components


【解决方案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

【讨论】:

    猜你喜欢
    • 2017-11-05
    • 1970-01-01
    • 2017-09-13
    • 2017-03-16
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2017-08-27
    • 2017-07-22
    相关资源
    最近更新 更多