Reputation: 11
i have create a method getProducts but not able to subscribe the response and getting the below error.
Property 'subscribe' does not exist on type '() => Observable<any>'
service file
public cartItemList :any = [];
public productsList = new BehaviorSubject<any>([])
constructor() { }
getProducts(){
return this.productsList.asObservable;
}
component.ts file
public totalItem:Number = 0;
constructor(private cartService:CartService){}
ngOnInit():void{
this.cartService.getProducts()
.subscribe((res:any)=>{
this.totalItem =res.length;})
}
Upvotes: 0
Views: 32
Reputation: 535
'asObservable' is a method not a property, so it´s just to add () and it should work.
getProducts(){
return this.productsList.asObservable;
}
should turn into:
getProducts(){
return this.productsList.asObservable();
}
Upvotes: 1