How to communicate between Angular DART controllers

前端 未结 3 1571
旧巷少年郎
旧巷少年郎 2020-12-04 02:49

i have two controllers and want to \"send\" between them object. I have something like this:

@NgController(selecto         


        
3条回答
  •  忘掉有多难
    2020-12-04 03:10

    With the newest AngularDart library (0.10.0), Günter Zöchbauer's solution is still correct, but the syntax has changed a bit:

    // Receiver
    //import 'dart:async';
    String name;
    Scope scope;
    ReceiverConstructor(this.scope) {
      Stream mystream = scope.on('username-change');
      mystream.listen(myCallback);
    }
    
    void myCallback(ScopeEvent e) {
      this.name = e.data;
    }
    
    
    // Sender
    scope.emit("username-change", "emit");
    scope.broadcast("username-change", "broadcast");
    scope.parentScope.broadcast("username-change", "parent-broadcast");
    scope.rootScope.broadcast("username-change", "root-broadcast");
    

提交回复
热议问题