Angular EventEmitter未在javascript插件回调中触发

时间:2016-11-24 05:41:50

标签: angular

从javascript插件的回调触发时未检测到EventEmitter 虚拟代码看起来像。

import { Component, OnInit, Output, EventEmitter, NgZone } from '@angular/core';
import { Router } from '@angular/router';
declare var $: any;
@Component({
    selector: 'my-component',
    templateUrl: 'app/component.html',
    styleUrls: ['app/component.css']
})
export class MyComponent implements OnInit {
    @Output() onComposing: EventEmitter<any> = new EventEmitter();
    private curUser: any;
    private JSONObj: any = null;
    constructor(private router: Router, private zone: NgZone) {
    }
    ngOnInit() {
        this.JSONObj = {
            onGetConfirmation: ()=> {
                this.notifyStatus();
            }
        }
        //works fine if I put code here event detected
        /*setInterval(()=>{
            this.onComposing.emit({
                date: (new Date()).getTime(),
                user: 'Some data' + (new Date()).getTime()
            });
        },1000);*/
    }
    notifyStatus(){
        this.zone.run(() => {
            //reaching here but not detected
            this.onComposing.emit({
                date: (new Date()).getTime(),
                user: 'some data' + (new Date()).getTime()
            });
        });
    }
    //triggered from UI
    doSomething(user: any) {
        var pluginInstance = this.plugin.getInstance();//from some plugin
        pluginInstance.toDoSomething(this.JSONObj);
    }
}

如果EventEmitter在setInterval块内触发,用于测试目的但是从javascript回调函数触发时没有正常工作

0 个答案:

没有答案