How do I refactor an `@Input` which is being updated directly, which is not possible to do in...

Discussão em 'Angular' iniciado por Naren Murali, Fevereiro 19, 2025.

  1. Naren Murali

    Naren Murali Guest

    I am refactoring my angular code to work with signals. I have this below code, which needs to be refactored.

    @Component({ ... })
    export class SomeComponent {
    @Input() test = null;

    ngOnInit() {
    this.test = 'qwerty';
    }
    ...


    There was no error when I update an @Input before input signal.

    Logically I would refactor this to:

    @Component({ ... })
    export class SomeComponent {
    test = input(null);

    ngOnInit() {
    this.test.set('qwerty'); // <- set does not exist for input signal
    }
    ...


    So in the above code, input signal does not have a set or update method, so my refactor is wrong, what is the logical way to solve this problem, the update must be done.

    Continue reading...

Compartilhe esta Página