In Angular 4 how we can change the parent component value when we are in child component?
Asked
Active
Viewed 1,068 times
-1
-
Possible duplicate of [Update parent component property from child component in Angular 2](https://stackoverflow.com/questions/41464871/update-parent-component-property-from-child-component-in-angular-2) – ochs.tobi Apr 18 '18 at 06:37
-
sir, i need this in angular 4 – Ankit Gupta Apr 18 '18 at 06:39
-
One of possible options is - both components may share same service: https://stackblitz.com/edit/two-sibling-components – happyZZR1400 Apr 18 '18 at 06:40
-
2 way data-binding is available in angular 4 aswell and is working just like that – ochs.tobi Apr 18 '18 at 06:40
-
Do you have some code to show ? – Yesub Apr 18 '18 at 06:41
2 Answers
0
Try this
child-component.ts
import { Component, OnInit, Input, Output,EventEmitter } from '@angular/core';
export class ChildComponent implements OnInit {
@Output() parentValue = new EventEmitter<string>();
onChange() {
this.parentValue.emit("test");
}
}
parent-component.html
<app-parent (parentValue)="parentValue"></app-parent>

Suvethan Nantha
- 2,404
- 16
- 28