Skip to content

Instantly share code, notes, and snippets.

@bonomiandreia
Created March 21, 2022 15:11
Show Gist options
  • Save bonomiandreia/44a3e05508c0d1b0cf9f9b1d24535b0c to your computer and use it in GitHub Desktop.
Save bonomiandreia/44a3e05508c0d1b0cf9f9b1d24535b0c to your computer and use it in GitHub Desktop.
input and output test!
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<app-value-provider (typedValue)="recivedValue($event)"></app-value-provider>
<app-value-receiver *ngIf="valueOfInput" [printValue]="valueOfInput"></app-value-receiver>
`,
})
export class AppComponent implements OnChanges {
valueOfInput: string;
recivedValue(event): void {
return this.valueOfInput = event;
}
ngOnChanges(): void {}
}
@Component({
selector: 'app-value-provider',
template: `
<input type="text" (change)="writing()" id="text"/>
`,
})
export class ValueProviderComponent {
@Output() typedValue = new EventEmitter<string>();
writing(): void {
let text = (<HTMLInputElement>document.getElementById('text')).value;
this.typedValue.emit(text);
}
}
@Component({
selector: 'app-value-receiver',
template: ` {{ this.printValue }}`,
})
export class ValueReceiverComponent implements OnInit {
@Input() printValue: string;
ngOnInit(): void {
console.log(this.printValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment