It has two main ways of sharing a state between two components that have no parent/child relationship. The first would be with Subject behavior with a service injected into the two components otherwise it would be by a state manager like the ngrx which follows the Redux standard.
Example with Subject behavior:
data.service.ts
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Data } from '../entities/data';
@Injectable()
export class DataService {
private dataSource = new BehaviorSubject<SnapshotSelection>(new Data());
data = this.dataSource.asObservable();
constructor() { }
updatedDataSelection(data: Data){
this.dataSource.next(data);
}
}
Its Component
constructor(private dataService: DataService) { }
dataService.data.subscribe(data => {
// use os dados aqui
})
dataService.updateData(newData);// para atualizar os dados
Source: https://medium.com/@weswhite/angular-behaviorsubject-service-60485ef064fc
doesn’t it pay to do a service for it? because if you do Output up to the level of the navbar will get mt ugly
– Gabriel Rodrigues
The fuck is that I need not redo requisition, then I even have service for it. The problem is the route check in this case;
– Willian Ferrera
a search in Snapshot of the angular.
– Guilherme Nunes
You can always try using store for your application this will give you access to the data in different parts of the application (eg https://ngrx.io/guide/store)
– diogoLima