Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Dart Angular, how to pass functions to component

I have a component MyComp and I would like to pass a function to it as parameter. More precisely I would like to do something like that:

dart component file:

 @NgComponent(
        selector: 'mycomp',
        publishAs: 'ctrl',
        map: const {
          'myfunc' :'=> myfunc'
        }
    )
class MyComponent {
   Function myfunc;

   ....
   myfunc();
}

html:

<mycomp myfunc="ctrl.myfunc"></button-list>

The problem is that myfunc is null in the component. Do I miss something? How can I do that?

like image 350
odwl Avatar asked Dec 07 '13 15:12

odwl


2 Answers

Use '&' to bind a function to a field:

@NgComponent(
    selector: 'mycomp',
    publishAs: 'ctrl',
    map: const {
      'myfunc' :'&myfunc'
    }
)
class MyComponent {
    Function myfunc;

   ....
   myfunc();
}

http://ci.angularjs.org/view/Dart/job/angular.dart-master/javadoc/angular.core/NgComponent.html#map

like image 62
Ozan Avatar answered Nov 16 '22 09:11

Ozan


The preferred way in AngularDart is to use annotations

@NgCallback('myfunc') Function myFunc;
like image 6
Günter Zöchbauer Avatar answered Nov 16 '22 08:11

Günter Zöchbauer