【发布时间】:2016-02-02 21:00:18
【问题描述】:
在 Angular 2 中,如何从父组件类访问子组件类?例如
import {Component, View} from 'angular2/core';
@Component({selector: 'child'})
@View({template: `...`})
class Child {
doSomething() {
console.log('something');
}
}
@Component({selector: 'parent'})
@View({
directives: [Child],
template: `<child></child>`
})
class Parent {
constructor() {
//TODO: call child.doSomething() when the child component is ready
}
}
在此示例中,我将如何从 Parent 组件的构造函数或某个回调函数调用 Child 组件的 doSomething() 方法。
【问题讨论】:
标签: typescript angular