Home > Back-end >  How to update input value in the same component in angular
How to update input value in the same component in angular

Time:11-27

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/app/table/table.component.ts

CodePudding user response:

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/app/table/table.component.html,src/app/table/table.component.ts,src/app/app.component.html,src/app/app.component.ts,src/app/change/change.component.html,src/app/change/change.component.ts,src/app/table/table.component.css

  • Related