按钮调用功能取决于来源

时间:2019-06-21 00:15:13

标签: angular

我有一个名为Header的组件,在内部有一个“ create”和“ Search”按钮,此Header位于客户,产品,销售页面中。我的问题是如何为每个页面执行创建和搜索功能。

我是否必须为每个页面创建3个创建按钮组件?

1 个答案:

答案 0 :(得分:2)

使用事件发射器:

export class ChildComponent {
    @Output() notifyParent: EventEmitter<any> = new EventEmitter();
    sendNotification() {
        this.notifyParent.emit('Some value to send to the parent');
    }
}

父组件html:

<child-component (notifyParent)="parentMethod()"></child-component>
相关问题