Property does not exist on type

311 views
Skip to first unread message

Ronald Faircloth

unread,
Feb 19, 2021, 2:49:01 PM2/19/21
to Angular and AngularJS discussion
I am getting an error that says "property does not exist on type" but the property does exist.  I am trying to use a forkJoin.  Here is the code for that:

  getCombined() {
    let mainHeaders = this.http.get<Header[]>(`${this.backendUrl}/api/header`);
    let subHeaders = this.http.get<Children[]>(`${this.backendUrl}/api/header/children`)

    forkJoin([mainHeaders, subHeaders]).subscribe(results => {
      results[0].children = results[1];
    })
  }

It says "property 'children' does not exist on type 'Header[]' but here is my header definition:

export class Header{
    headerID: number;
    headerName: string;
    hidden: boolean;
    children: Array<any>;
}

I have also tried:

import { Children } from '../definitions/children';

export class Header{
    headerID: number;
    headerName: string;
    hidden: boolean;
    children: Array<Children>;
}

Also:

children: Children;

and 

children: Children[];

in the above class.

What am I missing?  

Thank you in advance for any assistance!

Ronnie

Arnaud Deman

unread,
Feb 19, 2021, 3:10:13 PM2/19/21
to Angular and AngularJS discussion
Hi Ronald,

I think the backend is returning an array of header and not a single instance (and there is no children property in an array).
You can see what is returned in the console :
forkJoin ([mainHeaders, subHeaders]). subscribe (results => {
        console.log ('results', results);

        results [0] .children = results [1];
      })

The take operator can also be useful in some cases:
forkJoin ([mainHeaders, subHeaders]). smoking pipe (
      tap (result => console.log ('results', results)
) .subscribe (results => {

       results [0] .children = results [1];
      })

NB: there may be typos

Regards,
Arnaud.

Ronald Faircloth

unread,
Feb 19, 2021, 3:14:24 PM2/19/21
to ang...@googlegroups.com
Ahhh ok, that makes sense. You are correct, it is returning an array of type Headers. Thank you very much!

Ronnie

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/fd3ae297-d402-4b57-bacd-948c1cb3a3a0n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages