Ich habe Probleme beim Zusammenführen von 3 Objekte Array. Mein Ziel ist es, 3 Arrays zu einem zu verschmelzen und HTTP POST an den Server zu senden.Verschmelzen von Objekten in Angular 2
Ich habe mit concat versucht, aber ich bin diesen Fehler:
AUSNAHME: Fehler bei ./PreviewEmailPage Klasse PreviewEmailPage_Host - Inline-Vorlage: 0: 0, verursacht durch: Kann lesen Eigenschaft 'concat' undefinierter
nichtdas sind meine Codes:
import { Component } from '@angular/core';
import { NavParams, NavController, LoadingController } from 'ionic-angular';
import { Validators, FormGroup, FormControl } from '@angular/forms';
import { Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';
import { Storage } from '@ionic/storage';
@Component({
selector: 'preview-email-page',
templateUrl: 'preview-email.html',
})
export class PreviewEmailPage {
headers: Headers;
loading: any;
url: string;
preview: any[];
FirstArray: any[];
SecondArray: any[];
ThirdArray: any[];
PostData: any[];
constructor(
public nav: NavController,
public navParams: NavParams,
public loadingCtrl: LoadingController,
public localStorage: Storage,
public http: Http,
) {
this.localStorage.get('FirstArray').then((value) => {
this.FirstArray= value;
})
this.localStorage.get('SecondArray').then((value) => {
this.SecondArray= value;
})
this.localStorage.get('ThirdArray').then((value) => {
this.ThirdArray= value;
})
this.PostData = this.FirstArray.concat(this.SecondArray);
this.PostData = this.PostData.concat(this.ThirdArray);
this.loading = this.loadingCtrl.create();
}
ionViewWillEnter(){
this.headers = new Headers();
this.headers.append("Content-Type", "application/x-www-form-urlencoded");
console.log(this.PostData);
this.getPreview();
}
getPreview(){
this.loading.present();
this.url = 'https://domain.com/REST/getpreview.php';
this.http.post(this.url, this.PostData, {headers: this.headers}).map(res => res.json()).subscribe(res => {
console.log(res);
this.preview = res;
}, err => {
console.log('error');
})
}
}
Wie '.get vorgeschlagen (...) dann (...)' Ihr Abruf aus dem lokalen Speicher geschieht *. * asynchron **. Daher sind diese Felder zu der Zeit, zu der Sie zu der Verkettung gelangen, noch nicht festgelegt worden. – jonrsharpe