Contact DART Angular Controllers

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

@NgController(selector: '[users]', publishAs: 'ctrl')
class UsersController {
  List<Users> users;
}

@NgController(selector: '[user_logs]', publishAs: 'ctrl')
class LogsController {
  List<Log> logs;
  void filterLogsFor(User user) { logs = ... }
}

class MyAppModule extends Module {
  MyAppModule() {
    type(LogsController);
    type(UserController);
  }
}

My solution just added the LogsController to the UserController as a dependency and called something like ctrl.logsCtrl.filterLogsFor (user) from the template. But for some reason this will not work - I found that DI creates another new LogController object that is not related to the template itself - I even tried to change the value of "(LogsController, new LogsController ())", but it’s it - he creates a new LogsController when a new MyAppModule is called, and then a new one for the template. I'm obviously doing something wrong, but the documentation does not help, and angularjs seems completely different.

UPDATE: () - , .

+4
3

AngularDart (0.10.0) Günter Zöchbauer - , :

// 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");
+9

* scope.$emit
* scope.$broadcast
* scope.$on

@grohjy s .

Scope scope;
UserController(this.scope) { // get access to the scope by adding it to the constructor parameter list
  // sender
  scope.$emit('my-event-name', [someData, someOtherData]); // propagate towards root
  scope.$broadcast('my-event-name', [someData, someOtherData]); // propagate towards leaf nodes (children)
  scope.$parent.$broadcast('my-event-name', [someData, someOtherData]); // send to parents childs (includes silblings children)
  scope.$root.$broadcast('my-event-name', [someData, someOtherData]); // propagate towards leaf nodes starting from root (all nodes)

  // receiver
  scope.$on('my-event-name', (ScopeEvent e) => myCallback(e)); // call myCallback when an `my-event-name` event reaches me
}

scope.$emit ( ) ctrl + mouseclick, doc, .

+8

I am not fully following your question, could you include all the code for a better understanding.

Here is one example that might answer your question: https://github.com/angular/angular.dart/issues/264

+1
source

Source: https://habr.com/ru/post/1529835/


All Articles