In Dart Angular, how to pass functions to component

我怕爱的太早我们不能终老 提交于 2019-12-10 04:33:38

问题


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?


回答1:


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




回答2:


The preferred way in AngularDart is to use annotations

@NgCallback('myfunc') Function myFunc;


来源:https://stackoverflow.com/questions/20443278/in-dart-angular-how-to-pass-functions-to-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!