Is it possible to change the value of a variable that was decorated with Input()?

Asked

Viewed 29 times

0

I have the variable disciplinesTurma which was getting a value from the parent component. I wanted to remove one of its values, the method even removes, but only within itself. You can do it? inserir a descrição da imagem aqui

  • Mutation in general is bad, the right would be to copy to another property

1 answer

0

You can use a set method for this purpose. This way you run a logic before passing the value to your class variable. For example:

@Input()
set disciplinasTurma(disciplinas: string[]): void {
    this.disciplinasTurma = disciplinas.splice(disciplinas.findIndex(d => d === valor), 1);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.