0

Trying to update input value in the same component but not able to update.Getting error like

ERROR
Error: Cannot read properties of undefined (reading 'pop')

So, How to resolve this issue?

table.component.ts:

export class TableComponent implements OnInit {
@Input() names: any;

constructor() {}

ngOnInit() {}

testFn() {
  this.names.pop('Test22');
  this.names = [...this.names];
  console.log(this.names);
}

}

Demo : https://stackblitz.com/edit/angular-pass-table-data-to-input-property-dlsufy?file=src%2Fapp%2Ftable%2Ftable.component.ts

1 Answer 1

1

Jay Swaminarayan!

You are doing it slightly wrong while passing the Component Reference.

In ChangeComponent, it is not referencing the table component properly. In AppComponent HTML the table component must be passed as reference input to the changecomponent.

You may look at this corrected code

https://stackblitz.com/edit/angular-pass-table-data-to-input-property-2ehcxs?file=src%2Fapp%2Ftable%2Ftable.component.html,src%2Fapp%2Ftable%2Ftable.component.ts,src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fchange%2Fchange.component.html,src%2Fapp%2Fchange%2Fchange.component.ts,src%2Fapp%2Ftable%2Ftable.component.css

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.