I am currently working with a component named "myComponent" which is essentially a drop down button. I want to utilize this component in two different areas of my project - first in the navigation bar and then in the side nav specifically for mobile view. However, I need to dynamically change the image inside the component based on where it is being displayed, either in the navigation or in the side nav.
Within the myComponent, I am using
@Input() imgName: string = "imageOne"
. In the HTML template of the component, I am interpolating the variable like so <img ...src="../{imageOne}.png"
The issue arises when I render
<app-my-component [imgName]="imageTwo"></app-my-component>
from the navigation component and find that the value of imgName is undefined. Can anyone provide insight into why this might be happening?
https://i.sstatic.net/m4EPy.png
`export class MyComponent implements OnInit, AfterViewInit {
@Input() public imgName: string = "img_one";
constructor() { }
ngOnInit() {
console.log("Inside ng on init");
}
ngAfterViewInit(){
console.log("imgName value is: ${this.imgName}")
}
}
`
This is how I am rendering my component:
<app-my-component [imgName]="imageTwo"></app-my-component>