Wie man den Wert eines FormControl in angular2

Habe ich in das folgende Formular ein FormArray mit FormGroups

 <form [formGroup]="screenForm" novalidate>

  <div formArrayName="iPhoneScreenshots" class="row">
    <div *ngIf="screenForm.controls.iPhoneScreenshots?.length > 0">
      {{screenForm.controls.iPhoneScreenshots?.length }}
      <div *ngFor="let url of screenForm.controls.iPhoneScreenshots.controls; let i=index">
        <div [formGroupName]="i">
          <input class="form-control" formControlName="url">
          <img src="{{app.screenshotUrls[i]}}" class="rounded img-fluid app-screen" style="height:200px"/>
        </div>
      </div>
    </div>
  </div>
</form>

die url-Werte kommen aus einem array, die immer aufgefüllt, die via API
in der callback-ich habe die Werte:

private setScreenShots(app: ItunesApp): void {
if (app.hasOwnProperty('screenshotUrls')) {
  const screenShots = app.screenshotUrls.map(url => {
      return this.fb.group({
        url: [url, Validators.required]
      });
    }
  );
  const screenShotsArray = this.fb.array(screenShots);
  this.screenForm.setControl('iPhoneScreenshots', screenShotsArray);
 }
}

erste array ist leer

 private createForm() {
   this.appSiteForm = this.fb.group({
  title: ['', Validators.required]
});

this.screenForm = this.fb.group({
  iPhoneScreenshots: this.fb.array([]),
});

}

diese code-Zeile sieht schon sehr merkwürdig aus, um mich

img src="{{app.screenshotUrls[i]}}" 

Ich Tue dies, da url.Wert() oder url.get('value') wirft Fehler.

Also, wie kann ich den Zugriff auf den Wert eines Formular-Steuerelement?

InformationsquelleAutor dc10 | 2017-04-21

Schreibe einen Kommentar