在Dart Angular中,如何将函数传递给组件 [英] In Dart Angular, how to pass functions to component

查看:85
本文介绍了在Dart Angular中,如何将函数传递给组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组件MyComp,我想传递一个函数作为参数。
更准确地说,我想做这样的事情:

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组件文件

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

   ....
   myfunc();
}

html: b

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

问题是myfunc在组件中为null。
我错过了什么吗?

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

推荐答案

使用'&'将函数绑定到字段:

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

这篇关于在Dart Angular中,如何将函数传递给组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆