码迷,mamicode.com
首页 > 其他好文 > 详细

用EventEmitter收发消息

时间:2018-10-14 16:24:09      阅读:478      评论:0      收藏:0      [点我收藏+]

标签:width   定义   imp   struct   export   ble   tput   ring   this   

下面简单介绍其步骤。

《发消息 方》

1.import进EventEmitter

 import { EventEmitter } from ‘@angular/core‘;

2.在Component里定义事件接口 

@Component({
    selector: ‘sample-table‘,
    styleUrls: [‘sample-table.component.css‘],
    templateUrl: ‘sample-table.component.html‘,
    outputs: [onChangeExpand]
})

3.在类里定义事件

export class sample implements {
    onChangeExpand: EventEmitter<string>;

    constructor(public dialog: MatDialog){
        this.onChangeExpand = new EventEmitter();
     }

    // 一般处理
    onClickButton( ){
        // 送信
        this.onChangeExpand.emit(this.tempData.isExpant? "on" : "off");
    }
}

 

《收消息 方》

4.在模板里定义事件接收

<div>
  <table style="width: 98%;">
    <tr *ngFor="let data of datas">
      <sample [data]="data" onChangeExpand)="onChangeExpand($event)"></sample>
    </tr>
  </table> 
</div>

5.处理消息

onChangeExpand(msg: string){
   处理
}

 

很简单吧!

用EventEmitter收发消息

标签:width   定义   imp   struct   export   ble   tput   ring   this   

原文地址:https://www.cnblogs.com/nliao/p/9786248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!