ViewChild class

Declares a reference to a single child node in a component's template.

This annotation semantically similar to ViewChildren, but instead represents a single (or first, if more than one is found) node being queried

  • similar to querySelector instead of querySelectorAll.
  selector: 'child-cmp',
  template: '<p>child</p>',
class ChildCmp {}

  selector: 'some-cmp',
  template: '<child-cmp></child-cmp>',
  directives: [ChildCmp],
class SomeCmp {
  ChildCmp child;

See ViewChildren for a full documentation of parameters and more examples.


ViewChild(Object selector, {Object read})


descendants bool
Whether to query only direct children (false) or all children (true).
final, inherited
first bool
Whether to only query the first child.
final, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
read Object
The DI token to read from an element that matches the selector.
final, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
selector Object
Either the class Type or selector String.
final, inherited


noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]