6

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?

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

7 Comments

Great. To pass parameter, it there something simpler than myfunc({'\$myparam': xyz} with the html being <mycomp myfunc='ctrl.func($myparam)'> ?
Hmm, do you want to pass a parameter to mycomp when binding the function or from mycomp when calling myfunc?
I want to pass a parameter when calling myfunc.
Just call it like any other function. When binding it, in the html just write <mycomp myfunc='ctrl.func'>. Hint: '$' in identifiers is reserved for angular-specific members.
To pass parameters you'll need to pass a locals scope when calling the function: myfunc({'param1': paramVal1, 'param2': paramVal2}); and when binding <mycomp myfunc='ctrl.myfunc(param1, param2)'>
|
6

The preferred way in AngularDart is to use annotations

@NgCallback('myfunc') Function myFunc;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.