如何在<md-input> angular2中设置值

时间:2016-11-25 14:44:00

标签: angular angular2-forms

我从db获取数据,现在想设置数据 这是template.html:

 <div class="container">
  <div class="container-block">
    <form class="register" [formGroup]="form" (ngSubmit)="submitForm(form.value)" >

      <div class="info-block">
        <div class="image-block">
          <img src="../../assets/main/users.png" alt="">
          <div class="opacity"><a href="" class="photo-icon"></a></div>
        </div>
        <div class="person-info">
          <h2>John Smith</h2>
          <p>madcrocs@gmail.com</p>
        </div>
      </div>
      <div class="item" [ngClass]="{'indiv':!form.controls['username'].valid && form.controls['username'].touched}">
        <span>Username</span>
        <md-input  formControlName="username" class="demo-full-width">tyt</md-input></div>
    </form>
  </div>
</div>

组件代码是:

 this.form  = this.fb.group({
      username: ['HELLO', Validators.required],
      tags: ['', notEmpty]
    });

现在我想将HELLO视为输入值。我该怎么办?

1 个答案:

答案 0 :(得分:0)

您的代码中存在拼写错误:[formGroup]="form" vs [formGroup]="formP"