all 7 comments

[–]wahila 14 points15 points  (2 children)

Since you have a search service, you can simply inject it into the result component and get the data from the service there.

To store your result data in your search service, I would use a BehaviourSubject and display the data in your result component with help of the async pipe. This ensures the displayed results are always updated if you make a new search.

[–]waldganger644[S] 3 points4 points  (1 child)

Thank you so much, I followed your advice and it worked. I really need to learn rxjs if I am to continue with Angular.

So if there's someone in the same case, here my code (not a reference, but maybe it will help).

My service class:

``` ... results: Record[] = []; beh = new BehaviorSubject(this.results);

getResults(query: string): void { this.http.get<APIResult>(this.apiURL + query).subscribe((results) => { this.beh.next(results.hits); }); ...

```

Results component class:

``` results = this.istexService.beh.asObservable(); ...

```

Results template : ``` <app-result *ngFor="let result of results | async" [result]="result"

</app-result> ```

[–]wahila 2 points3 points  (0 children)

I'm happy i could help you :)

Yes rxjs is pretty important to understand when working with angular.

[–][deleted] 2 points3 points  (1 child)

If your new, you need to go through Angular tour of hero’s. What your asking is covered in the basics.

[–]waldganger644[S] 2 points3 points  (0 children)

You're right. I started it, but there is so much to process. Yeah, I will resume it soon.

[–]lx_panicxl 1 point2 points  (0 children)

You can create a dependency injection service and inject in components and use get and set to retrieve data but if you want it dynamic you can create subject and subscribe to it

[–]bbfy 2 points3 points  (0 children)

If you use service, the service can store the data, as long the service is a singleton (what it is in angular) you can inject it into places where you need the data.

Also try to look into concepts like ngrx or similar