Просмотр дочерних / просмотр дочерних от родительского компонента к дочернему компоненту - PullRequest
0 голосов
/ 10 октября 2018

Я хочу ViewChild от родительского компонента к дочернему компоненту.

class ParentComponent {
  @ViewChild('CommentSection') commentBox: ElementRef
}

class ChildComponent {}

child.component.html

<textarea #CommentSection>
 </textarea>

Возможно ли это?

Я получаю'undefined' в функции afterviewInit

1 Ответ

0 голосов
/ 10 октября 2018

Вы можете получить доступ к дочернему компоненту, как этот

import { Component, ViewChildren, AfterViewInit, QueryList } from '@angular/core';
import { MyComponent } from './mycomponent.component';

export class ParentComponent implements AfterViewInit
{

    @ViewChildren(MyComponent) childrenComponent: QueryList<MyComponent>;

    public ngAfterViewInit(): void
    {
        this.childrenComponent.changes.subscribe((comps: QueryList<MyComponent>) =>
        {
            // Now you can access the child component
        });
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...