Created
March 23, 2025 04:06
-
-
Save manoj10101996/4b6030f43d3a4556abadcd2c3da748b2 to your computer and use it in GitHub Desktop.
Accepting & Receiving data with input / output decorators properties [Parent to Child] - @input() , @output() decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<app-child-input-decorator [counter]="counterParent" (counterEmit)="receiveCounter($event)" ></app-child-input-decorator> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { ChildInputDecoratorComponent } from "./child-input-decorator/child-input-decorator.component"; | |
@Component({ | |
selector: 'app-root', | |
standalone: true, | |
imports: [ ChildInputDecoratorComponent], | |
templateUrl: './app.component.html', | |
styleUrl: './app.component.scss' | |
}) | |
export class AppComponent { | |
public counterParent:number = 25; | |
public receiveCounter(counter: number) { | |
this.counterParent = counter; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
Counter value: {{counter}} | |
</div> | |
<div class="my-2 card card-body"> | |
<input type="number" (input)="setCounter()" [(ngModel)]="counter" class="form-control"> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, EventEmitter, Input, Output } from '@angular/core'; | |
import { FormsModule } from '@angular/forms'; | |
@Component({ | |
selector: 'app-child-input-decorator', | |
standalone: true, | |
imports: [FormsModule], | |
templateUrl: './child-input-decorator.component.html', | |
styleUrl: './child-input-decorator.component.scss' | |
}) | |
export class ChildInputDecoratorComponent { | |
@Input() counter: number = 25; | |
@Output() counterEmit: EventEmitter<number> = new EventEmitter<number>(); | |
public setCounter() { | |
this.counterEmit.emit(this.counter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment