Skip to content

Instantly share code, notes, and snippets.

@zkkmin
Created June 30, 2018 23:17
Show Gist options
  • Save zkkmin/a1fa1db2ae9bd8e7795d20d7d0a8fb4d to your computer and use it in GitHub Desktop.
Save zkkmin/a1fa1db2ae9bd8e7795d20d7d0a8fb4d to your computer and use it in GitHub Desktop.
Calling child component's function from parent view
import { Component, ViewChild } from '@angular/core';
import { RandomQuoteComponent } from './random-quote/random-quote.component'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@ViewChild(RandomQuoteComponent)
private randomQuoteComponent: RandomQuoteComponent;
title = 'Muse';
onClickMe() {
this.randomQuoteComponent.getQuote();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment