I want to know if there is a better way to define the angular 2 callback functions of observed subscriptions when working with http calls without breaking the principle of uniform responsibility , when it comes to the built-in logic, it leads to an ugly dirty code .
I am trying to use function variables instead of arrow functions to separate callback logic, but I cannot access this and local function variables ( state in the example).
updateState(state: string) { let proposition = new Proposition(); proposition.id = this.id; proposition.state = state; this.propositionService.updateProposition(proposition).subscribe( (data) => { .... // instruction using local variable this.router.navigate(['/portfolio', state]); .... }, ..... // instrution using this (errors) => this.toastr.warning('Error.', 'ops !'); .....}
source share