ViewChild

ViewChild decorator

What it does

Configures a view query.

How to use

.

import {AfterViewInit, Component, Directive, ViewChild} from '@angular/core';

@Directive({selector: 'child-directive'})
class ChildDirective {
}

@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
class SomeCmp implements AfterViewInit {
  @ViewChild(ChildDirective) child: ChildDirective;

  ngAfterViewInit() {
    // child is set
  }
}

Description

You can use ViewChild to get the first element or the directive matching the selector from the view