我想将对象this.webCustomAlert、this.webCustomAuth、this.webCustomEcommerce组合成一个对象。它们都有共同的属性。所以我想从以下几个方面着手:
webCustomAuth
[{ "type":"google-login", "cost":30, "buildTime":2 },{ "type":"twitter-login", "cost":30, "buildTime":2 },{ "type":"facebook-login", "cost":30, "buildTime":2 }]webCustomAlert
[{ "type":"desktop-notifications", "cost":30, "buildTime":2 },{ "type":"web-notification-page", "cost":30, "buildTime":2 },{ "type":"web-notification-settings", "cost":30, "buildTime":2 }]webCustomEcommerce
[{ "type":"affiliate-url", "cost":30, "buildTime":2 },{ "type":"coupons", "cost":30, "buildTime":2 },{ "type":"discounts", "cost":30, "buildTime":2 }]至
webCustomFeatures
[{ "type":"affiliate-url", "cost":30, "buildTime":2 },{ "type":"coupons", "cost":30, "buildTime":2 },{ "type":"discounts", "cost":30, "buildTime":2 },{ "type":"desktop-notifications", "cost":30, "buildTime":2 },{ "type":"web-notification-page", "cost":30, "buildTime":2 },{ "type":"web-notification-settings", "cost":30, "buildTime":2 },{ "type":"google-login", "cost":30, "buildTime":2 },{ "type":"twitter-login", "cost":30, "buildTime":2 },{ "type":"facebook-login", "cost":30, "buildTime":2 }]这是我的代码:
public webCustomFeatures: any;
public webCustomAlert: any;
private webCustomAlertDataPath = './assets/data/web-custom-alert.json';
public webCustomAuth: any;
private webCustomAuthDataPath = './assets/data/web-custom-auth.json';
public webCustomEcommerce: any;
private webCustomEcommerceDataPath = './assets/data/web-custom-ecommercejson';
constructor(
public httpClient: HttpClient
) {
this.webCustom = this.httpClient.get(this.webCustomDataPath);
this.webCustomAlert = this.httpClient.get(this.webCustomAlertDataPath);
this.webCustomAuth = this.httpClient.get(this.webCustomAuthDataPath);
this.webCustomEcommerce = this.httpClient.get(this.webCustomEcommerceDataPath);
}
public getAllWebCustomAlert(): Observable<any> {
return this.webCustomAlert;
}
public getAllWebCustomAuth(): Observable<any> {
return this.webCustomAuth;
}
public getAllWebCustomEcommerce(): Observable<any> {
return this.webCustomEcommerce;
}
public getAllWebCustomFeatures(): Observable<any> {
const webCustomFeatures = [];
webCustomFeatures.push(this.webCustomAlert);
webCustomFeatures.push(this.webCustomAuth);
webCustomFeatures.push(this.webCustomEcommerce);
return webCustomFeatures;
}我一直收到错误消息Type 'any[]' is not assignable to type 'Observable<any>'. Property '_isScalar' is missing in type 'any[]'.
发布于 2019-06-07 01:32:34
您正在返回一个不可观测的可观测数据数组,您想要combineLatest
public getAllWebCustomFeatures(): Observable<any> {
return combineLatest(this.webCustomAlert, this.webCustomAuth, this.webCustomEcommerce);
}将发出和数组,一旦所有三个发出,那么您可以将数组分解为值。
getAllWebCustomFeatures().subscribe(([webCustomAlert, webCustomAuth, webCustomEcommerce]) => {
//Do stuff with the destructured values here
});https://stackoverflow.com/questions/56486673
复制相似问题