Skip to content

[Ivy] @ViewChild doesn't read me ElementRef #28643

@wKoza

Description

@wKoza

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Maybe, it seems to be available if we read this status

Description

I'm testing Ivy on a little application with the beta.3 but I have a component like this:

@Component({
    selector: 'tracklist',
    templateUrl: './tracklist.component.html',
    styleUrls: ['./tracklist.component.css'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class TracklistComponent implements AfterViewInit {
...
    @ViewChild('matTable', {read: ElementRef}) elRef;

constructor(private route: ActivatedRoute, private renderer: Renderer2) { }


ngAfterViewInit() {
...
  this.renderer.setStyle(this.elRef.nativeElement, 'overflow-y', 'hidden');
}

When I run ng serve --aot and I instantiate this component, I have this error:


Error TypeError : Cannot read property 'nativeElement' of undefined

elRef is always undefined.

🌍 Your Environment

Angular Version:


Angular CLI: 7.2.4
Node: 10.10.0
OS: darwin x64
Angular: 8.0.0-beta.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.4
@angular-devkit/build-angular     0.12.4
@angular-devkit/build-optimizer   0.12.4
@angular-devkit/build-webpack     0.12.4
@angular-devkit/core              7.2.4
@angular-devkit/schematics        7.2.4
@angular/cdk                      7.3.1
@angular/cli                      7.2.4
@angular/material                 7.3.1
@ngtools/webpack                  7.2.4
@schematics/angular               7.2.4
@schematics/update                0.12.4
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.28.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimefreq1: lowneeds reproductionThis issue needs a reproduction in order for the team to investigate furthertype: bug/fix

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions