0
votes

I want to create interaction between components which are not parents or children : they are in different NgModules. I imagined a service, where I inject my component, but it seems to not be possible. And I can't inject too my component in the other component (cause they are not parent/child). But they have a common parent (AppComponent). How could I do to make communicate my components ?

1
I'm searching a case where components are not parent or child - Pythorogus
That's what the linked docs cover as well. - Günter Zöchbauer

1 Answers

0
votes

You definitely can use services. Something like that:

import { EventEmitter } from '@angular/core';

export class SharedService {
    pushedData = new EventEmitter<string>();
    private data: string[] = [];

    addData(input: string) {
        this.data.push(input);
    }

    getData() {
        return this.data;
    }

    pushData(value: string) {
        this.pushedData.emit(value);
    }
}