Angular. ViewChild, ViewChildren, ContentChild и ContentChildren

Angular предоставляет 4 декоратора свойств @ViewChildren, @ViewChild, @ContentChildren и @ContentChild для доступа к дочерним элементам:

  • @ViewChild - querySelector
  • @ViewChildren - querySelectorAll
  • @ContentChild - querySelector внутри <ng-content>
  • @ContentChildren - querySelectorAll внутри <ng-content>

viewchildren-viewchild-contentchildren-and-contentchild

  1. <todo-input> и <todo-item> рассматривается как ViewChildren <todo-app>
  2. <app-footer> (если он определен как Angular компонент или директива) рассматривается как ContentChild.

Похожие записи

RxJs Subjects

Выдержки из доклада Андрея Алексеева (Tinkoff) про RxJs (Subject, Behaviour Subject, Replay Subject, Async Subject). Применение в Angular.

Angular routerLink conditionally

<a [routerLink]="myVar ? '/home' : null" routerLinkActive="is-active">Home</a>
or
<a [routerLink]="myVar ? ['/home'] : []">Home</a>
02 сентября 2019 г. в Angular