As Bhushan said, ngFor is a structural directive so it's a shortcut for a template-based structure. In short, it can be desugared into the following in your template:
<template ngFor let-office [ngForOf]="employee.offices">
<tr (click)="selectOffice(input)">
(...)
</tr>
</template>
The way to define local variable for templates is the following:
- Add the prefix
let-. For example, let-office will define a variable office.
- If you don't define a value, the value of the
$implicit entry in the template context will be used. In the case of ngFor, it's the current element in the iteration. Here: let-office.
- You can also specify a value. For example, if you want to define a variable for the index in the loop:
let-i="index". In the case, the variable i will contain the corresponding value.
Regarding variables define with the # prefix. They correspond to a DOM element if the element they apply on isn't a component. If it's a component, it corresponds to the component. For example, input in <input #input/> corresponds to an ElementRef and the DOM element can be accessed through its nativeElement property.
You can also specify a value for such variables. In this case, you can select a specific directive applied on the element. For example <input #ctrl="ngModel" [(ngModel)]="val"/>. The value corresponds to what is specified within the exportAs attribute in the directive declaration:
@Directive({
selector: 'child-dir',
exportAs: 'child'
})
class ChildDir {
}
@Component({
selector: 'main',
template: `<child-dir #c="child"></child-dir>`,
directives: [ChildDir]
})
class MainComponent {
}