Skip to content

Instantly share code, notes, and snippets.

@karthikchintala1
Created August 26, 2017 13:10
Show Gist options
  • Save karthikchintala1/a371d1ca384dfd5cf8d5f444cc5cf022 to your computer and use it in GitHub Desktop.
Save karthikchintala1/a371d1ca384dfd5cf8d5f444cc5cf022 to your computer and use it in GitHub Desktop.
Toggling the child component using @ViewChild. For more, visit https://angularman.wordpress.com
import {Component, ViewChild} from '@angular/core'
import {ToggleComponent} from './child.component.ts'
@Component({
selector: 'my-app',
template: `
<div style="color: red;">
<h2>Parent Component</h2>
</div>
<div>
Toggle child component:
<input type="button" value="Toggle" (click)="toggleChild()"/>
</div>
<toggle></toggle>
`,
})
export class App {
@ViewChild(ToggleComponent) child: ToggleComponent;
name:string;
constructor() {
this.name = `Angular! v${VERSION.full}`
}
toggleChild() {
this.child.toggle();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment