angular - 当父组件中的选择发生(更改)时如何在子组件中执行函数

标签 angular

我有一个子组件,我想在父组件中的选择触发 (change) 事件后调用该函数。这可能吗?

最佳答案

是的,你可以使用@ViewChild

试试这个:

父组件:

HTML:

<select (change)="selectDropdownChange()">
    <option >...</option>
</select>

<child-comp #childRef></child-comp>

TS:

@ViewChild('childRef') childRef: ChildComp;

selectDropdownChange() {
    this.childRef.childFunction();
}

关于angular - 当父组件中的选择发生(更改)时如何在子组件中执行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56337879/

相关文章:

angular - 如何将 Web3js 导入 Ionic/Angular 项目?

javascript - 使用 PHP 包装器从 wkhtml 生成 PDF,发送回 Angular 4 时,仅在 Chrome 中打开

node.js - 您似乎不依赖 "@angular/core"。 typescript

typescript - @ngrx/store-devtools : instrumentStore() returns an array of objects instead of providers

angular - IntelliJ 理念 : custom imports path

Angular2 相当于 angular.isArray

php - 调用图像时 laravel 直接路径中的 Cors Origin

javascript - 将字符串日期转换为 JavaScript 日期

angular - 在 TS 2.8 中使用 TextEncoding 和 Angular 6

angular - 无法验证 Angular 5