Reporter | Kees Wiegel (iwantwin) |
---|---|
Created | Nov 29, 2018 5:22:04 PM |
Updated | Nov 29, 2018 5:22:04 PM |
State | Submitted |
Assignee | Unassigned |
Subsystem | No Subsystem |
Type | Bug |
Priority | Normal |
Browser | Any Browser |
OS | Any OS |
Fix versions | Unscheduled |
Affected versions | Unknown |
What steps will reproduce the problem?
- Create any angular component
- Add '#example' to any tag in your template, making it a template reference variable
- Use @ViewChild('example') to reference said element
What is the expected result?
Not showing a message that the template reference variable is unused.
What happens instead?
The template reference variable is reported as 'unused local variable'
Please provide any additional information below.
Component:
import { Component, ViewChild, ViewContainerRef } from '@angular/core';
@Component( {
selector: 'some-test',
templateUrl: './test.component.html',
styleUrls: []
} )
export class TestComponent {
@ViewChild( 'example', { read: ViewContainerRef } ) set dynamicRef( example: ViewContainerRef ) {
console.log( 'example was updated: ', example );
};
constructor() {
}
}
Template:
<div>
<ng-container *ngIf="true">
<div #example> <!-- #example is reported as `Unused local variable example` -->
</div>
</ng-container>
</div>
It seems to be a quite isolated use case:
- removing the *ngIf makes it being recognized as 'used'
- removing the <div>, making the ng-container the root element, makes it being recognized as 'used'
Tested on 29/11/2018:
Build #IU-183.4284.148, built on November 21, 2018
JRE: 1.8.0_152-release-1343-b15 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0```