'Is #myId the same as id="myId" in HTML? [duplicate]

While taking an angular course I read the following code:

<p *ngIf="serverCreated;else noServer">{{serverName}}  {{serverCreationStatus}}</p>
<ng-template #noServer>
  <p>No server was created</p>
</ng-template>

I wonder if the expression #noServer is equivalent to the expression id="noServer". Is this way of doing specific to Angular? Is it recommended to use this way of defining the id?



Solution 1:[1]

The #noServer is what's called a template variable. It's not the same as an id attribute. It allows Angular to reference the element it's placed on, either from within the template:

<div *ngIf="myCondition; else otherDiv"></div>
<div #otherDiv>

Or from TypeScript using @ViewChild, for example:

@ViewChild('otherDiv') otherDiv: ElementRef

For more information, see Angular docs https://angular.io/guide/template-reference-variables

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Will Alexander