角度2的@Output不起作用

时间:2017-11-15 21:03:33

标签: angular-cli

我正在使用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 没有收到任何东西

1 个答案:

答案 0 :(得分:0)

绑定事件时使用函数:

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

和主要组件ts写入功能

ClosedInMainFN(event: boolean) {

this.isClosedinMain = event;

}