У меня есть несколько служб, которые получают http-ответ от сервера.
export abstract class ServiceBase<T>{
getAll(){console.log(`${this.url}/${this.endpoint}`)
return this.http.get<any[]>(`${this.url}/${this.endpoint}`);
}
get(id: any){
return this.http.get<any>(`${this.url}/${this.endpoint}/${id}`);
}
}
@Injectable()
export class Service1 extends ServiceBase<any> {
constructor(http: HttpClient) {
super(http, "http://localhost:60211", "s1");
}
}
@Injectable()
export class Service2 extends ServiceBase<any> {
constructor(http: HttpClient) {
super(http, "http://localhost:60211", "s2");
}
}
@Injectable()
export class Service3 extends ServiceBase<any> {
constructor(http: HttpClient) {
super(http, "http://localhost:60211", "s3");
}
}
И я использую это в приложении.
export class AppComponent {
s1: {};
s2: any[];
s2: any[];
constructor(service1:Service1, service2:service2, service3:service3){
service1.get("123").subscribe({
next: response => {
this.s1=response;
service2.getAll().subscribe({
next: response => {
this.s2 = response;
}
});
service3.getAll().subscribe({
next: response => {
this.s3 = response;
}
})
}
})
}
}
Но ответы s3 и s2 не приходят с сервера,Это это использование ложно? Но когда я запускаю сервис из почтальона, сервис работает.