我正在设置一个支持web和app(使用cordova)的新角度应用程序。问题是如何动态扩展适用于两种环境的抽象类。
我有类似的环境配置。
environment.app.ts
{
url: 'https://localhost',
isAppEnv: true
}
environment.web.ts
{
url: 'http://example.com',
isAppEnv: false
}
此摘要将用于网络
export abstract class ProductOnWebService {
constructor(protected http: HttpClient) { }
abstract description();
updateProductDetail(data): Observable<any> {
const url = environment.url + '/products?productId=' + data.id;
const params = JSON.stringify({params: data});
return this.http.post(url, params).map(res => res);
}
}
此摘要将用于应用程序
export abstract class ProductOnWebService {
constructor(protected http: HttpClient) { }
abstract description();
updateProductDetail(data): Observable<any> {
const url = environment.url + '/products/' + data.id;
const params = JSON.stringify(data);
return this.http.post(url, params).map(res => res.data);
}
}
如何在环境上扩展抽象?
books.service.ts
@Injectable()
export class BookProductService extends ??? {
constructor(private http: HttpClient) {
super(http);
}
description() {
return {name: '', description: '', prize: 1000};
}
}