How to use input signal in service?

Discussão em 'Angular' iniciado por Galdor, Dezembro 3, 2024.

  1. Galdor

    Galdor Guest

    I have a component which gets an array as an input signal:

    export class MembersComponent {
    members = input.required<Member[]>();


    and a service

    constructor (private service: MyService) {}


    the service is provided by a parent component.

    How do I pass the value of members to the service? Is this OK?

    class MyService {
    members = computed(()=>[]) // will be overridden by component


    Now I can set the method in the component with:

    this.service.members = computed(()=>this.members());


    I can do it in the constructor or in ngOnInit, but it does not satisfy me, is there a more elegant solution?

    Continue reading...

Compartilhe esta Página