簡體   English   中英

在Angular 4中,當我們處於子組件中時,如何更改父組件的值?

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

在Angular 4中,當我們處於子組件中時,如何更改父組件的值?

使用@OutputEventEmitters將數據從子組件發送到其父組件。 您可以找到有關官方文檔的教程

嘗試這個

子組件

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM