0

I have angular 5 project with the following structure:

app.component.html

<app-header></app-header>
<app-list-view></app-list-view>
<app-footer></app-footer>

In my <app-header> component I have a <app-search></app-search> component:

<div id="headerContent">
    <div id="logo">
        <img src="../../../assets/images/logo.png"/>
    </div>

    <app-search></app-search>
</div>

In this search.component.html I have:

<div id="searchContent">
  <input [(ngModel)]="queryString" type="text" placeholder="Bijv. PHP developer, AngularJs"/>
  <button>Zoeken</button>
</div>

I would like to pass the data from the input field from the app-search component to the app-list-view component.

What would be the best way to do this?

Peter Boomsma
  • 8,851
  • 16
  • 93
  • 185

1 Answers1

2

The easiest way to achieve communication between components that are not nested (aka parent-child) it to use a service. A useful example is the on in Angular docs.

tasos
  • 369
  • 1
  • 9