如何在angularjs2中对可观察数据进行subcibe

时间:2016-08-23 05:05:27

标签: angular typescript

我有一个编辑按钮,我通过该按钮传递学生ID,然后单击我在表单中显示学生详细信息,但问题是我在那里有可观察性并且我在那里被击中。有人请帮帮我....

我的模板标记

 <form  [formGroup]="form" (ngSubmit)="onSubmit(form.value)"  >
   First name:<br>
      <input    [formControl]="form.controls['name']" [(ngModel)]="details.name"  type="text" name="firstname">
          <br>
     Age:<br>
  <input    [formControl]="form.controls['age']" [(ngModel)]="details.age"   type="text" name="age">
     <button  type="submit">Save</button>
  </form>

我的Ts,

    edit(id): any {
    //console.log(id);
    this.property = 'update';
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded')
    this.http.get('http://localhost/a2server/index.php/profile/editprofiledb/' + id, { headers: headers })
        .subscribe(response => {
            if (response.json().error_code == 0) {
                this.details = <IStudent2[]>response.json().data;

            } else {
                this.details = <IStudent2[]>response.json().data;
             }

            })
}

0 个答案:

没有答案