6

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

飞镖组件文件:

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

   ....
   myfunc();
}

html:

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

问题是组件中的 myfunc 为空。我错过了什么吗?我怎样才能做到这一点?

4

2 回答 2

7

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

@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

于 2013-12-07T16:21:56.453 回答
6

AngularDart 中的首选方式是使用注解

@NgCallback('myfunc') Function myFunc;
于 2013-12-07T16:04:55.640 回答