Reputation: 233
i am new in angular and i am trying to upgrade the angular 4 to newest a ngular, i tried to make reusable a class method, to use it on many services and component
let say that this file called:
./base-services.services.ts :
getDataParam(url: any, params: any) {
return this.http
.get(url, { params: params })
.pipe(catchError(this.handleError))
.subscribe(response => response);
}
createData(url: any, data: any) {
return this.http
.post(url, data)
.pipe(catchError(this.handleError))
.subscribe(response => response);
}
and i use that base-services to extends on all services i make
./getData.services.ts :
export class LegalorderService extends BaseService {
private token: string;
constructor(http: HttpClient, auth: AuthService) {
super(http);
auth.isAuthenticated();
this.token = auth.token;
}
getCart() {
let params = { access_token: this.token };
return this.getDataParam(
Configuration.BASE_URL + Configuration.GET_SAVED_CART,
params
);
}
}
and on the component :
updateValue() {
this.legalOrderService.getCart().subscribe(response => {
if (response.message != "ERROR") {
this.localStorageService.store("legalOrder", response.result);
this.localStorageService.store(
"cartItems",
response.result.order_details
);
this.cartTotal = this.localStorageService.retrieve("cartItems");
}
});
}
do i wrong to use subscribe on that component from services ??
and after that i get error like this :
ERROR in node_modules/rxjs/internal/Subscription.d.ts(16,3): error TS2374: Duplicate string index signature.
node_modules/rxjs/internal/Subscription.d.ts(17,3): error TS2393: Duplicate function implementation.
node_modules/rxjs/internal/Subscription.d.ts(17,44): error TS1183: An implementation cannot be declared in ambient contexts.
node_modules/rxjs/internal/Subscription.d.ts(20,3): error TS2393: Duplicate function implementation.
node_modules/rxjs/internal/Subscription.d.ts(20,44): error TS1183: An implementation cannot be declared in ambient contexts.
node_modules/typescript/lib/lib.es5.d.ts(124,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'string'.
node_modules/typescript/lib/lib.es5.d.ts(127,5): error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'string'.
node_modules/typescript/lib/lib.es5.d.ts(130,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'string'.
node_modules/typescript/lib/lib.es5.d.ts(133,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'string'.
node_modules/typescript/lib/lib.es5.d.ts(139,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'string'.
node_modules/typescript/lib/lib.es5.d.ts(145,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'string'.
node_modules/typescript/lib/lib.es5.d.ts(151,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'string'.
Upvotes: 0
Views: 93
Reputation: 1062
You are trying to subscribe on a subscription:
getDataParam
updateValue
Remove subscribe
from getDataParam
:
getDataParam(url: any, params: any) {
return this.http
.get(url, { params: params })
.pipe(catchError(this.handleError));
}
Upvotes: 1
Reputation: 7931
One issue I can see in your code is , you don't need to subscribe multiple times , just remove the subscribe from the getDataParam method , because you are already subscribing in the component.
getDataParam(url: any, params: any) {
return this.http
.get(url, { params: params })
.pipe(catchError(this.handleError));
}
Upvotes: 0