javascript - Cannot read variable data of child view -


i have component mycomponent , declared this:

export class mycomponent implements icomponent {     ...     @input() departments: any;         @input() dropdownoptions: any;         @input() data: any[];     ... } 

however, there no property data, when try access personcomponent component.

html of personcomponent component:

<fieldset>     <my-comp #mygrid [options]="ps.options['mygrid']"></my-comp> </fieldset> 

typescript of personcomponent component:

export class personcomponent implements oninit {         @viewchild('mygrid') mygridcomponent: mycomponent;      ngafterviewinit() {         debugger;                 let localdata2 = this.mygridcomponent.data; // no data property. undefined      }      ngaftercontentinit() {         debugger;                 let localdata1 = this.mygridcomponent.data; // no data property. undefined            }  } 

variables can seen @ debugger of chrome:

enter image description here

how can read values of data property of mycomponent? doing wrong?

@input data ... decorator "receives" data parent component. set via attribute [data] inside parent template. if don't set it indefined. on other hand have [options] attribute doesn't have corresponding @input in child.

you can fix so:

<fieldset>     <my-comp #mygrid [data]="person.data"></my-comp> </fieldset> 

where person array data field in parent component.

please read thoughtfully documention https://angular.io/guide/template-syntax#inputs-outputs , https://angular.io/guide/component-interaction#pass-data-from-parent-to-child-with-input-binding

and better not use reserved/too generic name data, options avoid name collisions , camel case them.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -