小编Mah*_*upu的帖子

如何在formbuilder数组中设置值

我有一个关于将数组值设置为 formBuilder.array 的问题。在不是数组的 formBuilder 中,它可以使用这种方式来设置值,但在 formBuilder.array 中我不能这样做。我尝试为 formbuilder 'listServiceFeature' 和 'listservicefeature' 设置值,但无论如何都没有设置值。

ts

listServiceFeature: any = ['m1', 'm2']

contentFormValidate(): void {

  this.contentForm = this.formBuilder.group({
          'listservicefeature': this.formBuilder.array([
              this.formBuilder.group({
                 listServiceFeature: ['', [Validators.required]
              });
          ]),
  });

  this.contentForm.controls['listservicefeature'].setValue(this.listServiceFeature);
}


addServiceFeature() {
    const control = <FormArray>this.contentForm.controls['listservicefeature'];
    control.push(this.initServiceFeature());
}

removeServiceFeature(i: number) {
    const control = <FormArray>this.contentForm.controls['listservicefeature'];
    control.removeAt(i);
}
Run Code Online (Sandbox Code Playgroud)

html

<div formArrayName="listservicefeature">
  <div class="form-group" *ngFor="let servicefeature of contentForm.controls.listservicefeature.controls; let i=index">
    <label for="Service">Features {{i+1}}</label>
    <div class="input-group" [formGroupName]="i">
        <input type="text" class="form-control" formControlName="listServiceFeature">
        <template [ngIf]="i == 0">
            <span class="input-group-btn">
            <button …
Run Code Online (Sandbox Code Playgroud)

angular2-formbuilder angular

10
推荐指数
2
解决办法
1万
查看次数

Angular 2 Http delete在体内发送json

Angular2可以通过http方法删除发送json正文吗?

我试了,它说错了

ORIGINAL EXCEPTION: options.search.clone is not a function
Run Code Online (Sandbox Code Playgroud)

service.ts

deletetag(tagid: number): Observable<any> {

    let body = JSON.stringify(
        {
            "token": "test",
            "content": {
                "tagId": tagid
            }
        }
    );

    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });

    return this.http.delete("http://localhost:8080/backend/tag", body, options)
        .map(res => this.extractData(res))
        .catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)

component.ts

this.tagService.deletetag(1)
   .subscribe(
      data => { },
      error => { },
      () => { }
   );
Run Code Online (Sandbox Code Playgroud)

angular2-services angular

3
推荐指数
1
解决办法
8385
查看次数

如何从循环 ngFor 中的 input type="text" 获取输入值

我有关于从 ngFor 中的 input type="text" 获取值的问题,而我将它与 [(ngModel)] 绑定,所有这些都具有相同的值,我如何绑定 ngFor 中的所有输入?

html

<button (click)="saveFeature()" type="button">save</button>

<input class="form-control" type="text" />
<button (click)="addFeature()" type="button">Add</button>

<div *ngFor="let inputservice of servicesfeature_id; let i=index">
  <input class="form-control" [(ngModel)]="listServiceFeature" type="text" />
  <button (click)="RemoveFeature(i)" type="button">Remove</button>
</div>
Run Code Online (Sandbox Code Playgroud)

成分

servicesfeature_id: any = [];
servicesfeature_length: number = 0;
listServiceFeature: any = [];
servicefeature_name: string;

saveFeature(): void {
  console.log(this.listServiceFeature);
}

addFeature(): void {
  this.servicesfeature_id.push('service' + this.servicesfeature_length);
  this.servicesfeature_length += 1;
}

RemoveFeature(index): void {
  this.servicesfeature_length -= 1;
  this.servicesfeature_id.splice(index, 1);
}
Run Code Online (Sandbox Code Playgroud)

这是代码plnkr.co

angular

1
推荐指数
1
解决办法
2万
查看次数