如何解决如何在子组件中构建通用更改功能以用于不同的父组件?角度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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。