Skip to content

Instantly share code, notes, and snippets.

@alexzuza
Last active May 19, 2018 18:07
Show Gist options
  • Save alexzuza/768bbfa3115de3dec8764ba33eb308bd to your computer and use it in GitHub Desktop.
Save alexzuza/768bbfa3115de3dec8764ba33eb308bd to your computer and use it in GitHub Desktop.
Example ivy
@Component({
selector: 'my-app',
template: `
<h2>Parent</h2>
<child [prop1]="x"></child>
`
})
export class AppComponent {
x = 1;
}
@Component({
selector: 'child',
template: `
<h2>Child {{ prop1 }}</h2>
<sub-child [item]="3"></sub-child>
<sub-child *ngFor="let item of items" [item]="item"></sub-child>
`
})
export class ChildComponent {
@Input() prop1: number;
items = [1, 2];
}
@Component({
selector: 'sub-child',
template: `
<h2 (click)="clicked.emit()">Sub-Child {{ item }}</h2>
<input (input)="text = $event.target.value">
<p>{{ text }}</p>
`
})
export class SubChildComponent {
@Input() item: number;
@Output() clicked = new EventEmitter();
text: string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment