Родительский класс
import { BadRequestError } from './../common/bad-request-error';
import { NotFoundError } from './../common/not-found-error';
import { AppError } from './../common/app-error';
import { Http } from '@angular/http';
import { Injectable, OnInit } from '@angular/core';
import { catchError } from 'rxjs/operators';
import { throwError} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private url: string , private http: Http) {
}
getAll() {
return this.http.get(this.url).pipe(catchError(this.handleError));
}
delete(id) {
return this.http.delete(this.url + '/' + id)
.pipe(
catchError(this.handleError));
}
update(resource) {
return this.http.patch(this.url + '/' + resource.id,
JSON.stringify({isRead: true})).pipe(
catchError(this.handleError));
}
create(resource) {
return this.http.post(this.url , JSON.stringify(resource))
.pipe(
catchError(this.handleError)
);
}
private handleError(err: Response) {
if (err.status === 404) {
return throwError(new NotFoundError());
} if (err.status === 400) {
return throwError(new BadRequestError(err.json()));
}
return throwError(new AppError(err));
}
}
Детский класс
import { DataService } from './data.service';
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class PostService extends DataService {
constructor(http: Http) {
super('https://jsonplaceholder.typicode.com/posts' , http);
}
}
Ошибка ниже при передаче строки из дочернего класса.
Ошибка: StaticInjectorError (AppModule) [String]:
StaticInjectorError (Платформа: ядро) [Строка]:
NullInjectorError: Нет поставщика для строки!
в NullInjector.push ../ node_modules/@angular/core/fesm5/core.js.NullInjector.get
(core.js: 1062)
at resolToken (core.js: 1300)
в tryResolveToken (core.js: 1244)
at StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get
(core.js: 1141)
at resolToken (core.js: 1300)
в tryResolveToken (core.js: 1244)
at StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get
(core.js: 1141)
at resolNgModuleDep (core.js: 8376)
на NgModuleRef_.push ../ node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get
(core.js: 9064)
при вводе (core.js: 1403)
, пожалуйста, предложите, как решить вышеуказанную ошибку.