p zankat
p zankat

Reputation: 135

how to pass parameters in angularjs custom directive for function call

This is my code snippet -

<my-wizard
        on-finish="doFinish()"

I am calling on-finish from my-wizard's controller class. It works and doFinish() gets invokes. I want to pass some parameters to doFinish() from the directive controller. What is the way for it?

This is my-wizard directive -

app.directive('myWizard', function () {
    return {
        restrict: 'EA',
        replace: true,
        transclude: true,
        scope: {        
           onFinish: '&',
           ...
           }
        }

Upvotes: 0

Views: 101

Answers (1)

mindthefrequency
mindthefrequency

Reputation: 546

Where is your onFinish() method getting called?

just pass some data to it in the shape of an object

onFinish({someData: data})

Then retrieve it using the same name of the object property:

function doFinish(someData) {
   console.log(someData)
}

The directive definition should also cater the passed argument:

<my-wizard
    on-finish="doFinish(someData)"

Upvotes: 1

Related Questions