Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Last active May 9, 2020 11:04
Show Gist options
  • Select an option

  • Save AvocadoVenom/f8d991a41cfdeecbb219b410cce9a6c4 to your computer and use it in GitHub Desktop.

Select an option

Save AvocadoVenom/f8d991a41cfdeecbb219b410cce9a6c4 to your computer and use it in GitHub Desktop.
Several ways to make an angular child-to-parent communication
import { Component} from '@angular/core';
@Component({
selector: 'app-child',
template: `<h1>I am the child</h1>`
})
export class ChildComponent {
message = 'Hey there from the child!';
constructor() { }
}
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { ChildComponent } from "./child.component";
@Component({
selector: 'app-parent',
template: `
Message: {{ message }}
<app-child></app-child>
`
})
export class ParentComponent implements AfterViewInit {
@ViewChild(ChildComponent) child;
message:string;
constructor() { }
ngAfterViewInit() {
this.message = this.child.message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment