3

I may be missing the obvious here, but is it possible to bind data into an angular.dart controller? Being an annotation, it can take an attribute map, but since there's no HTML involved in (directly) creating the controller, how does one bind those attributes?

More to the point, lets say I use two controllers on one page. One is reusable (A), the other isn't (B) - hence the separation. If A needs to work with data from B, how do I go achieving that?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
AlexM
  • 33
  • 2
  • You could look at: [Mutation-Observer as Best Dart Practice](http://japhr.blogspot.com.au/2014/02/mutationobserver-as-best-dart-practice.html). That said, I think Dart design needs to take _one-step-back_ and look at an event model. Polymer and Mutation both '_think_' only in terms of the shadow-DOM. – will May 04 '14 at 12:17

1 Answers1

0

As you provided no concrete example nor code of what you want to accomplish I'm not sure what you really want.

You can use the attribute map you mentioned or annotations like mentioned here

You can bind to any attribute on the element the controller is associated with and get the value assigned to the controller. This is the same as with component or directive.

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Well, my question is where exactly do I do the binding? For components and directives there's a HTML tag and its attributes get bound. But the controller is created behind the scenes, I'm not sure how I can tell what gets inhected in this case. – AlexM Jan 29 '14 at 08:41
  • You mean when you let inject a controller in the constructor of a ... component? I have only used controllers which are created like directives or components. I have a selector like `@NgController(selector: '[ng-controller=mycontroller', publishAs: 'ctrl') class MyController { @NgTwoWay('an-attribute') String anAttribute; }` If you don't do it this way I guess you can't, you can then only access the scope. – Günter Zöchbauer Jan 29 '14 at 08:44
  • That is what I want. The questions is, where does 'an-attribute' come from? Remember, I need one controller to work with data from another one. – AlexM Jan 29 '14 at 09:06
  • if you have `
    ` then you get the value of the parent scope (if any is publishedAs `pctrl`) bound to `MyController.anAttribute`
    – Günter Zöchbauer Jan 29 '14 at 09:11
  • Excellent. So, like I guessed, I _was_ missing the obvious. – AlexM Jan 29 '14 at 09:18