Search code examples
javascriptangularcrossfilter

error TS: 2339 Property "Project" does not exist on type { }


I am using crossfilter js library in my Angular 2 + project, As per documentation of crossfilter, Crossfilter API accepts array of javascript objects. Using a service I am getting data from mongo db, using observable I am getting data in form of array of Object.

below is service call in my component

this._getdataservice.getData().subscribe(  
    function (posts) {
        console.log(posts);
        var ndx = crossfilter(posts);
        var projectDim = ndx.dimension(function(d) { return d.Project });
    }
)

I am Getting error as shown in below screen shot enter image description here

If I print post object in console it is giving array of object

enter image description here

Code written in service

getData(): Observable<any>  {
    return this.http.get<any>(this.url);
}

code written in component in which service is injected

constructor(private _getdataservice: DataServiceService) { }

ngOnInit() { 
    this._getdataservice.getData().subscribe(function(posts){
        console.log(posts);
        var ndx = crossfilter(posts);
        var projectDim = ndx.dimension(function(d) {return d.Project});
    })
}

Please help me to understand where I am doing wrong?


Solution

  • Change the type of d as any

    var projectDim = ndx.dimension(function(d : any) { return d.Project};