How to pass values from child to parent component in Angular 4

后端 未结 2 1403
执笔经年
执笔经年 2020-12-16 19:01

I am working in an Angular4 application ,In I\'m trying to pass values from child component to parent component .I have implemented something but I can\'t get the output as

相关标签:
2条回答
  • 2020-12-16 19:29

    In angular 4 you can use @Input, @Output decorators for values or Emit the data.

    Please refer https://angular.io/guide/component-interaction

    0 讨论(0)
  • 2020-12-16 19:40

    You are emitting the value by using event emitter sendCount. You have to receive it in parent component by using child component like this:

    parent.html

    <app-my-cart (sendCount)="customFunc($event)"></app-my-cart>
    

    parent.ts

    customFunc(data){
        this.totalcartval = data;
    }
    

    Also, there are other ways of communicating like subject in rxjs or by using shared service.

    0 讨论(0)
提交回复
热议问题