-1

In Angular 4 how we can change the parent component value when we are in child component?

2 Answers2

2

Use @Output and EventEmitters to send data from a child components to it's parent. You can find tutorials on the offical docs

Fussel
  • 1,740
  • 1
  • 8
  • 27
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