I am trying to subscribe a function in service but getting error that "Property 'subscribe' does not exist on type 'void' " i used normal Subject to subscribe to the values here although i am emitting the values in the service file Below is the code where i subscribe to the function in service file
component.ts file
import { Subscription } from 'rxjs';
export class AllproductsComponent implements OnInit {
category
filter
allprodcuts
constructor(private prservice:ProductService,private
router:Router,private route:ActivatedRoute) { }
subscription:Subscription
ngOnInit() {
this.route.queryParams.subscribe(params=>{
console.log(params)
this.category=params
})
this.subscription=this.prservice.getallproductsinallprodcuts()
.subscribe( //Here i am facing the error
(r)=>{
this.allprodcuts=r
console.log(r)
}
)
}
}
service file
import { Injectable } from '@angular/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { Product } from '../products.modal';
@Injectable({
providedIn: 'root'
})
export class ProductService {
productslist=new BehaviorSubject<any>(1)
getalllist=new Subject<any>()
cards:any[]=[
{
id: 0,
imageurl: "https://butterwithasideofbread.com/wp-
content/uploads/2012/07/Easiest-Best-Homemade-
Bread.BSB_.IMG_6014.jpg"
,price: "4"
,select: "Dairy"
,title: "Bread"
},
{
id: 1
,imageurl: "https://butterwithasideofbread.com/wp-
content/uploads/2012/07/Easiest-Best-Homemade-
Bread.BSB_.IMG_6014.jpg"
,price: "23"
, select: "Bread"
,title: "udemy"
}
]
constructor() {
}
addtocards(values){
values.id=this.cards.length
this.cards.push(values)
this.productslist.next(this.cards.slice())
// console.log(this.cards)
}
getallproducts(){
return this.cards
}
getproductbyid(id){
return this.cards[id]
}
update(valuestobeupdated,id){
this.cards[id]=valuestobeupdated
this.cards[id].id=id
this.productslist.next(this.cards.slice())
}
getallproductsinallprodcuts(){
this.productslist.next(this.cards.slice())
}
}