angular - 如何在子组件中构建通用(更改)函数以用于不同的父组件?角度 9
问题描述
我希望能够在子组件中构建一个“通用”(更改)函数,以用于具有不同行为的一个或多个父母。
我试图用@input 做一些事情,但问题是我必须直接将事件(更改)放在子模板中。如何将其放置在父模板中?
孩子
import { Component, Output, EventEmitter, Input } from "@angular/core";
@Component({
selector: "select-state",
template: `select name="" #selectstate >
<option selected > {{ selectStartMessage }}</option>
< option[value]="state.stateCode" * ngFor="let state of states" > {{ state.stateName }}</option>
< /select>`,
styleUrls: []
})
export class SelectState {
@Input() callback: Function;
constructor() { }
}
家长 1
<section class="container">
<div class="row">
<div class="col-11">
<select-state (change)"FunctionParent1()"></select-state>
</div>
</div>
</section>
家长 2
<section class="container">
<div class="row">
<div class="col-11">
<select-state (change)"FunctionParent2()"></select-state>
</div>
</div>
</section>
解决方案
推荐阅读
- arrays - 如何使用“properties”关键字解释这个 OpenAPI 数组定义?
- angular - NGXS @Selector() 从其他状态触发。但为什么?
- json - 如何反序列化包含带有更多 JSON 的字符串的 JSON?
- qt - 当按下具有不同选项的另一个按钮时,如何隐藏菜单按钮中的额外选项?
- sql - 如何在具有 LAG 函数的列中填充非空值旁边的多个空值?请建议
- excel - Power Query - 复制多列 Mcode
- laravel - laravel 属于同一张表 不是唯一的表/别名
- git - 如果删除包含文件夹,Git 会停止跟踪已删除的文件
- ssl - 禁用 SSL 时 Rs.exe 无法发布报告
- python - Generate n random values from a specific mean and range values