Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to pass template variable to other component included in current component but getting undefined error. Not sure what wrong I'm doing. Below is the component html and ts file code.

JavaScript
<div *ngIf=dataLoaded>
    <div #topDiv id="topDiv"></div>
</div> 
<scroll-content [targetElmRef]="target"></scroll-content>


JavaScript
@Input('targetElmRef') targetElmRef: any;


What I have tried:

above is the code snippet

<pre lang="Javascript">
<div *ngIf=dataLoaded>
    <div #topDiv id="topDiv"></div>
</div> 
<scroll-content [targetElmRef]="target"></scroll-content>


JavaScript
@Input('targetElmRef') targetElmRef: any;
Posted
Updated 5-Mar-19 20:48pm
v2

1 solution

You would really need to post both the parent and the component code to make it clear what you're doing, but something like:

Parent component:

JavaScript
<div *ngIf=dataLoaded>
    <div #topDiv id="topDiv"></div>
</div> 
<scroll-content [targetElmRef]="target"></scroll-content>


With the parent component typescript:

get target() : any {
 return targetObject.
}


And on the child component:

@Input targetElmRef: any;


Should work if you return whatever you;re aiming to bind the child component to.

Make sure that target is defined, and you should probably define the types rather than use 'any' as it'll make it more readable.
 
Share this answer
 
v3
Comments
[no name] 5-Mar-19 13:40pm    
This worked, thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900