angular-material2 - 文本框值与占位符值重叠

时间:2017-01-06 09:27:38

标签: angular angular2-forms angular-material2

以下代码如果放在http中,则不会正确设置文本框值。文本框值与占位符值重叠。

 this.http.get('tes.json')
  .map(response => response.json())
  .subscribe(result => {
    (<FormGroup>this.form)
        .setValue({food: "test", food1: '123123'}}, {onlySelf: true});
  });

这里是plunker https://plnkr.co/edit/aKZZ9vLLykVSMf3oqFEg?p=preview,下面的图片展示了问题

enter image description here

但如果我们在这样的http之外设置formgroup值,那么工作正常。

(<FormGroup>this.form)
    .setValue({food: "test", food1: '123123'}}, {onlySelf: true});

有人能让我知道造成这个问题的原因吗?

3 个答案:

答案 0 :(得分:0)

您的this范围未加载。

let _self = this;
this.http.get('tes.json')
  .map(response => response.json())
  .subscribe(result => {
    (<FormGroup>_self.form)
        .setValue({food: "test", food1: '123123'}}, {onlySelf: true});
  });

答案 1 :(得分:0)

问题是由新的mdInput实施引起的。下一个版本中将有一个修复程序( 2.0.0-beta.2 )。

你可以......

  • 等待它,
  • 抓住当前的主人或
  • 返回旧的<md-input>元素,直到新版本发布。

当您对导致此问题的原因感兴趣时,this pull request应该已经解决了问题。

答案 2 :(得分:0)

在测试版中仍有此问题。

如果我点击表单中的一个输入..它修复了该表单中的所有输入

...我现在的解决方法是为输入调用click事件