joelkesler / angular-share-objects-instead-of-values

Passing Objects vs Passing Values for sharing data between children and parent components in Angular

Home Page:https://stackblitz.com/edit/angular-ivy-aqinhv

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing Objects vs Passing Values for sharing data between children and parent components in Angular

From a Vendasta internal tech demo.

Try on StackBlitz ⚡️

When you pass an object as an input to a component, it's used as a reference/pointer to the original object. Any change you make to that object in a child component are shared between everything using that object.

If you pass in a bare value/variable (string, number, boolean, etc) then the value is duplicated, and changes made by a child component are not shared with anything else using that value/variable.

In the Angular Email Builder I used this to keep the main email data object updated when the user edited the email.

About

Passing Objects vs Passing Values for sharing data between children and parent components in Angular

https://stackblitz.com/edit/angular-ivy-aqinhv


Languages

Language:TypeScript 64.9%Language:HTML 34.0%Language:CSS 1.1%