Although the accepted answer is correct and links to a document with the answer, I thought it was worth unpacking the explanation a bit more.
tl;dr – this syntax #var="directiveExportAsName"
is useful for targeting a specific directive on an element if there are multiple directives applied to the element.
Long answer
Specifically, it is unpacked in the "Variable specifying a name" section.
The code example being:
<form #itemForm="ngForm" (ngSubmit)="onSubmit(itemForm)">
<!-- removed for brevity -->
</form>
<div [hidden]="!itemForm.form.valid">
<p>{{ submitMessage }}</p>
</div>
Their explanation (emphasis mine):
The NgForm
directive demonstrates getting a reference to a different value by referencing a directive's exportAs
name...
Without the ngForm
attribute value, the reference value of itemForm
would be the HTMLFormElement
, <form>
. If an element is an Angular Component, a reference with no attribute value will automatically reference the component instance. Otherwise, a reference with no value will reference the DOM element, even if the element has one or more directives applied to it.
For this particular case <mat-menu #menu="matMenu">
, although the official examples use it, I don't think it is necessary. According to the doc, "If an element is an Angular Component, a reference with no attribute value will automatically reference the component instance," and since the selector mat-menu
and exported as name matMenu
refer to the same component directive, it is therefore redundant.