I found this similar question, but it doesn't explain what's going on with assignments to template reference vaiables...
I'm making a toolbar with dropdown menus using @angular/cdk
's OverlayModule
.
In order to have multiple dropdown menus, I have to assign the cdkOverlayOrigin
directive to it's template reference variable.
<span #mytrv1="cdkOverlayOrigin">...<span>
<span #mytrv2="cdkOverlayOrigin">...<span>
so that I can access them individually with a @ViewChild
of type CdkOverlayOrigin
@ViewChild('mytrv1') mytrv1: CdkOverlayOrigin;
@ViewChild('mytrv2') mytrv2: CdkOverlayOrigin;
It seems odd to me to assign a directive to a variable like this #mytrv1="cdkOverlayOrigin"
. Can anyone explain this pattern?