I have an object Person being passed on from a parent component as shown below. The name is initialized to an empty string when declaring the property before ngOnInit(). The property is used to set a boolean in another component. Even though the parent component has a value of name = John in the parent component, scenario 1 wipes that value out to an empty string thus affecting the boolean. Scenario 2 does not alter the value of name = John. What is the difference between the two assignments in scenario 1 and 2? and why is scenario 1 wiping out the original value in the parent component?
export interface IPerson {
name?: string;
}
// In a child component:
@Input() person: IPerson = { name: '' }
// scenario 1:
ngOnInit(): void {
this.person.name = '';
}
// scenario 2:
ngOnInit(): void {
this.person = { name: '' }
}