1

I'm trying to bind a function (this.getData) to a variable (rating) within the constructor of a directive:

@NgDirective(
    selector: '[spreadsheet]',
    map: const {
    'rating' : '<=>rating'
    })

class Spreadsheet {
  dom.Element element;

  Function rating;

  getData(){
    return context.callMethod(r'$', [this.element])
    .callMethod('handsontable', ['getData']);
  }

  Spreadsheet(this.element) {
  context.callMethod(r'$', [this.element])
   .callMethod('handsontable', [new JsObject.jsify(options)]);

  **rating = this.getData;**
  }
}

and it seems that "rating" is not assigned with "this.getData" when I access it:

<p spreadsheet rating="rating"></p>
{{rating()}}

the "rating" is null. This is not the case when I do the binding for example when mouse enters the element:

...
Spreadsheet(this.element) {
   element
  ..onMouseEnter.listen((ev){this.rating = this.getData;});
...

and the binding occurs fine when mouse enters the element (rating is not null). How this can be fixed?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Amir Dezfouli
  • 199
  • 3
  • 10

1 Answers1

0

If you assign the function in the constructor you won't need

 'rating' : '<=>rating'

You can call any method from your expressions in markup. The map or annotations (What is the annotation equivalent of map: const {'foo':'&foo'} in AngularDart?, What is the equivalent annotation for the old map/@attr in AngularDart?) are only for synchronizing attribute and field values.

If you also want to be able to assign the function from the outside you need @ instead of <=> or @NgCallback('rating') (see What is the equivalent annotation for the old map/@attr in AngularDart?)

You should set publishAs: 'ctrl' and call the method using {{ctrl.rating()}}

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • can I expose a directive as by 'publishAs'? What I want to achieve is the reverse of "NgCallBak", i.e., I want to be able to call a method of a component/directive from outside to get the data from. – Amir Dezfouli Feb 13 '14 at 12:45
  • Your comment is to abstract for me. Can you extend you question with a simple example which describes what you actually try to achieve `` I want that inner calls xxx on outer... – Günter Zöchbauer Feb 13 '14 at 12:52