After adding the changes to the parent let’s move to child component. Changes needs to be done in the child.component.ts
and child.component.html
file.
import { Component, Input, Output, OnInit, EventEmitter } from "@angular/core";
@Component({
selector: "app-child",
templateUrl: "./child.component.html",
styleUrls: ["./child.component.scss"],
})
export class ChildComponent implements OnInit {
@Input() input1!: string;
@Input() input2!: string;
@Output() newInput = new EventEmitter<string>();
constructor() {}
ngOnInit(): void {}
temporaryInput!: any;
addInputNumbers(temporaryInput: any) {
this.newInput.emit(temporaryInput);
}
}
<app-grand-child
[input1]="input1"
[input2]="input2"
(newInput)="addInputNumbers($event)"
>
</app-grand-child>
In last final changes needs to be done in the grand-child.component.ts
and grand-child.component.html
file.
import { Component, OnInit, Input, Output, EventEmitter } from "@angular/core";
@Component({
selector: "app-grand-child",
templateUrl: "./grand-child.component.html",
styleUrls: ["./grand-child.component.scss"],
})
export class GrandChildComponent implements OnInit {
@Input() input1!: string;
@Input() input2!: string;
@Output() newInput = new EventEmitter<string>();
constructor() {}
ngOnInit(): void {}
temporaryInput!: any;
addUserInput() {
this.temporaryInput = parseInt(this.input1) + parseInt(this.input2);
this.newInput.emit(this.temporaryInput);
}
}
<button (click)="addUserInput()">Add Numbers</button><br /><br />
HTTP in Angular
Previously
How to create carousel in angular?
Coming up next