Angular Dart component events

后端 未结 2 1105
执念已碎
执念已碎 2020-12-19 18:56

I am trying to pass custom events from a component to its parent component/controller

confirm.html

2条回答
  •  一生所求
    2020-12-19 19:29

    Based on the answer from Günter i built this working example:

    @Component(
        selector: "confirm-component",
        templateUrl: 'component/confirm.html',
        useShadowDom: false,
        publishAs: "ctrl"
    )
    
    class ConfirmComponent implements ScopeAware {
        Scope scope;
    
        void yes(){
            scope.emit('confirm', 'yes');
        }
    
        void no(){
            scope.emit('confirm', 'no');
        }
    }
    
    @Component(
        selector: "my-component",
        templateUrl: 'component/my.html',
        useShadowDom: false,
        publishAs: "ctrl"
    )
    class MyComponent implements ScopeAware{
    
        void set scope(Scope scope) {
            Stream mystream = scope.on('confirm');
            mystream.listen((event){
                print('confirmed: ' + event.data);
            });
        }
    }
    

提交回复
热议问题