角度 2 中的@Output不起作用



我正在使用Angular 2。所以子组件是

import { Component, OnInit,  Output, EventEmitter } from '@angular/core';
...
    export class EnterComponent implements OnInit {
        @Output() isClosedChange = new EventEmitter<boolean>();
        public isClosed: boolean;
        constructor() {
            let isClose = true;
         }
        Close() {
            this.isClosed = false;
            this.isClosedChange.emit(this.isClosed);
        }
    }

我的父公司是

export class AppComponent {
    public isClosedinMain: boolean;
    constructor() {
        this.isClosedinMain = true;
    }
}

和 html:

<app-header (isClosedChange) = "isClosedinMain"></app-header>

它非常简单,但isClosedinMain没有收到任何东西

绑定到事件时,请使用函数:

<app-header (isClosedChange) = "ClosedInMainFN($event)"></app-header>

和主组件 TS 写入函数

ClosedInMainFN(event: boolean) {
this.isClosedinMain = event;
}

最新更新