Reputation: 670
I work on angular 7 app I face error property subscribe doesn't exist on type
void when subscribe data from service .
error display on subscribe data function on app.component.ts so How to solve this issue if possible ?
allReportCategories:any[];
ngOnInit() {
this._displayreport.getallReportCategories().subscribe((data: any[]) => {
this.allReportCategories = data;
});
}
on display report service ts
allReportCategories:any[];
getallReportCategories(){
return
this.allReportCategories=[
{
"reportCategoryID": 1,
"reportCategory": "Dashboard Parametric",
"isDeleted": false,
"menuIcon": "icon-home"
},
{
"reportCategoryID": 2,
"reportCategory": "Monitor Reports",
"isDeleted": false,
"menuIcon": "icon-list"
},
{
"reportCategoryID": 3,
"reportCategory": "Other Reports",
"isDeleted": false,
"menuIcon": "icon-docs"
},
{
"reportCategoryID": 4,
"reportCategory": "PCN Flow",
"isDeleted": false,
"menuIcon": "icon-list"
},
{
"reportCategoryID": 5,
"reportCategory": "Compliance By Document",
"isDeleted": false,
"menuIcon": "icon-home"
}
];
}
sample exist on stackbliz as below :
https://stackblitz.com/edit/create-1arrvm?file=app%2Fdisplayreport.service.ts
to more specific on my question
what i change here :
this._displayreport.getallReportCategories().subscribe
Upvotes: 0
Views: 221
Reputation: 500
you need to create observable to subscribe
example:-
in display report service ts
import { BehaviorSubject } from 'rxjs';
getallReportCategories(){
const allReportCategories = [
{
"reportCategoryID": 1,
"reportCategory": "Dashboard Parametric",
"isDeleted": false,
"menuIcon": "icon-home"
},
{
"reportCategoryID": 2,
"reportCategory": "Monitor Reports",
"isDeleted": false,
"menuIcon": "icon-list"
},
{
"reportCategoryID": 3,
"reportCategory": "Other Reports",
"isDeleted": false,
"menuIcon": "icon-docs"
},
{
"reportCategoryID": 4,
"reportCategory": "PCN Flow",
"isDeleted": false,
"menuIcon": "icon-list"
},
{
"reportCategoryID": 5,
"reportCategory": "Compliance By Document",
"isDeleted": false,
"menuIcon": "icon-home"
}
];
return new BehaviorSubject(allReportCategories)
}
in component
allReportCategories:any[];
ngOnInit() {
this._displayreport.getallReportCategories().subscribe((data: any[]) => {
this.allReportCategories = data;
});
}
Upvotes: 1