I have 2 divisions, for example divisions Left and Right, the server side urls for these divisions are the same except for the division name for example:
'/api/Left/DoThisThing';
or
'/api/Right/DoThisThing';
I have this in my HttpService
(simplified):
@Injectable()
export class MyHttpService {
constructor(private http: Http) { }
private baseUrl = '/api/';
private selectedDivision: Divisions = Divisions.Left;
getAll(): Observable<Test[]> {
return this.http.get(this.baseUrl + Divisions[this.selectedDivision])
.map((response: Response) => response.json())
.catch((error: any) => Observable.throw(error.json().error || 'An unknown server error occurred while trying to get all.'));
}
selectDivision(division: Divisions) { this.selectedDivision = division; }
}
Of course, the problem is that calling selectDivision(Divisions.Right)
does nothing until I click on the nav link that forces the child component that subscribes to getAll()
to reload.
The way I'd prefer to do this is to notify all subscribers of getAll()
to retry that endpoint... or perhaps cause that get
request to retry with the newly updated url. How do I do it? If there a better way to do this?