PX *_*per 0 observable eventemitter output angular-components angular
我有Angular Component一个Output.当我emit的event此output,一个async功能将被调用(该功能部件的外部).
在里面component,我想知道这个外部功能何时完成.有没有办法做到这一点?
这是我的组件的一些代码:
@Output() action: EventEmitter<string>;
itemClicked(item) {
    this.action.emit();
    // When the function of the observer is done: this.hideMenu();
}
Run Code Online (Sandbox Code Playgroud)
这是组件外部的代码:
<my-component (action)="getData()"></my-component>
getData() : Promise<any> {
    ...
}
Run Code Online (Sandbox Code Playgroud)
有没有办法检测到"getData"函数已在组件内部完成?
在AngularJS中,我可以这样做:
scope: {
    action: '&'
}
...
    scope.itemClicked = function(item) {
        $q.when(item.action()).finally(function() {
            scope.hideMenu();
        });
    };
Run Code Online (Sandbox Code Playgroud)
编辑:
我正在思考另一个灵感来自Ionic复习的解决方案.如果emit()调用将组件的实例作为参数传递,该怎么办?这样getData函数可以执行以下操作:
getData(menu): Promise<any> { 
    ...
    menu.hideMenu();
}
Run Code Online (Sandbox Code Playgroud)
您对此解决方案有何看法?如果你认为这是错的,那么我想我会选择Input.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           721 次  |  
        
|   最近记录:  |