Edit: I have uploaded the project to StackBlitz
CodePudding user response:
After checking your code on stackblitz, I recoment you to refactor the code a little
- Don't keep data in components. You should move the function to a Service
- I created the service and added "add" method in one
- Data moves beetwen service and component with help an observable
so, your refactored code is below https://stackblitz.com/edit/angular-ivy-exyyf6?file=src/app/services/message.service.ts