당신은보기 아이
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
@Component({
selector: 'child-cmp',
template: '<p>child</p>'
})
class ChildCmp {
doSomething() {}
}
@Component({
selector: 'some-cmp',
template: '<child-cmp></child-cmp>',
directives: [ChildCmp]
})
class SomeCmp {
@ViewChild(ChildCmp) child:ChildCmp;
ngAfterViewInit() {
// child is set
this.child.doSomething();
}
}
하여이 작업을 수행 할 수 있습니다 또는 당신은 또한 문자열
로 할 수있는
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
@Component({
selector: 'child-cmp',
template: '<p>child</p>'
})
class ChildCmp {
doSomething() {}
}
@Component({
selector: 'some-cmp',
template: '<child-cmp #child></child-cmp>',
directives: [ChildCmp]
})
class SomeCmp {
@ViewChild('child') child:ChildCmp;
ngAfterViewInit() {
// child is set
this.child.doSomething();
}
}
감사합니다 @ Karty; – Shay
환영합니다. 내 질문에 투표를 찾고. – Karty