In my application, I am creating an embedded view and am passing a context to it.
thumbnailTemplateRef:TemplateRef<ThumbnailContext>;
...
let thumbnailContext = new ThumbnailContext(divId,
buttonId,
imgId,
closeId,
imageString,this.thumbnailContainerRef.length,null);
console.log("saving image context ",thumbnailContext);
thumbnailTemplateViewRef = this.thumbnailContainerRef.createEmbeddedView(this.thumbnailTemplateRef, thumbnailContext);
In the HTML, I am trying to access the context in the following way.
<ng-template #thumbnailTemplate let-context="thumbnailContext">
<div id="{{context.divId}}">
<button id="{{context.buttonId}}" type="button" data-toggle="modal" (click)="showEnlargeImage(context)">
<img id="{{context.imgId}}" src="{{context.imgSrc}}"/>
<a *ngIf="this.isEditing" href="javascript:void(0)" id="{{context.closeId}}" (click)="deleteThumbnailFromContainer(context)"></a>
</div>
</ng-template>
I see the following print in the console.
saving image context
ThumbnailContext {divId: "thumbnail-1", buttonId: "thumbnail-button-1", imgId: "img-1", closeId: "close-button-1", imgSrc: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYA…7Jj8HyDnRt/ePaJ5eXn8Azv0jA3o5lvcAAAAASUVORK5CYII=", …}
buttonId: "thumbnail-button-1"
closeId: "close-button-1"
divId: "thumbnail-1"
imgId: "img-1"
imgSrc: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABVYA"
index: 0
viewRefId: null
__proto__: Object
But I am getting the following error during execution
Cannot read property 'divId' of undefined
correspoding to the html code <div id="{{context.divId}}">
What am I doing wrong here?