사용자 도구

사이트 도구


angular:component-interaction

Component Interaction

From the parent component To the child component

1.Parent Component

<app-test-component-interaction [parentData]="name"></app-test-component-interaction>

2.Child Component

export class TestComponentInteractionComponent implements OnInit {
  //@Input() public parentData;
  @Input('parentData') public name;
  constructor() { }
  ngOnInit() {
  }
}

From the child component To the parent component

1.child component

  <h2>Hello {{ name }}</h2>
  <button (click)="firstEvent()">Send Event</button>
export class TestComponentInteractionComponent implements OnInit {
  @Input('parentData') public name;
  @Output() public childEvent = new EventEmitter();
 
  constructor() { }
 
  ngOnInit() {
  }
  firstEvent(){
    this.childEvent.emit('Hey Taekgu');
  }
}

2.parent component

<div>Child message: {{ message }}</div>
<app-test-component-interaction (childEvent)="message=$event" [parentData]="name"></app-test-component-interaction>
angular/component-interaction.txt · 마지막으로 수정됨: 2025/04/15 10:05 저자 127.0.0.1