0

Trying to access the remove function from child component(chips-autocomplete-example). But not able to access it in app.component. When i click the close (X) icon, i want to get the value of that. For example, if i click the Apple close icon, i want to get the Apple text in the alert. Same like for others(Lemon, Lime, Orange, Strawberry) I am doing this from the app.component ts file. But not working. How to resolve this?

app.component.ts:

  removeClick(removeval) {
    alert(removeval);
  }

app.component.html:

<chips-autocomplete-example
  (removed)="removeClick(fruit)"
></chips-autocomplete-example>

Demo: https://stackblitz.com/edit/angular-sbrx2p-k89gvp?file=app.component.ts

1

1 Answer 1

1

Not sure if I'm understand your problem correctly, but from child do parent (in the easiest way) you can use @Output() removed = new EventEmitter<string>(); and in remove function add this.removed.emit(fruit) in child and then in parent

<chips-autocomplete-example
  (removed)="removeClick($event)"
></chips-autocomplete-example>
Sign up to request clarification or add additional context in comments.

2 Comments

Can you edit my stackblitz?
stackblitz.com/edit/angular-sbrx2p-q6t4sx you stackblitz was almost good ;) just replace in app.component.html removeClick(fruit) with removeClick($event)

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.