Search code examples
angularservicecomponentsobservable

Angular Observable Component and Service Interaction


What would the update TODO function call look like with Corey Rylan’s code example: https://stackblitz.com/edit/angular-fh1kyp ?

Specifically, if I have a todo: Observable<Todo> in the Angular Component, how do I call update( todo: Todo ) of the Angular Service?


Solution

  • Not very sure about what you are looking for but have you tried subscribing to the todo variable of type observable and then calling the update function from inside the subscribe function?

    todo.subscribe(todoValue => this.service.update(todoValue));
    

    What this will do is subscribe to the todo Observable and whenever something is received, it will call the update function.