0

I use a datepicker which returns a selected date as a value to its callback the datepicker is a plugin.

In my callback method selectedDate i need to pass in additional parameters such as the dateValue to this selectedDate method. How can i achieve this

<datepicker callback="selectedDate" ></datepicker>


 $scope.selectedDate= function (dateValue) {

}
3
  • is selectedDate in controller? and how the selectedDate looks like in controller? Commented Dec 3, 2015 at 7:23
  • Yes, I have updated the code with the callback defined in the controller. Commented Dec 3, 2015 at 7:27
  • 1
    plnkr.co/edit/NnhkVvcuAhlVX9v7fxrG?p=preview Commented Dec 3, 2015 at 7:39

1 Answer 1

1

So what you need is to specify the kind of params that you are expecting back, http://plnkr.co/edit/0fqMLYlEeBwQylo2Va1B?p=preview

You directive basically asks for the variables on execution,

<test-dir callback="callback(a, b , c)"></test-dir>

and while execution you pass these values back:

 app.directive('testDir', function() {
  return {
    restrict: 'E',
    scope: {
      callback: '&'
    },
    template: '<div ng-click="testFunc()">click me</div>',
    link: function(scope) {
      scope.testFunc = function() {
         scope.callback({a: 1, b : 2, c: 3});
      } 
    }
  }
})
Sign up to request clarification or add additional context in comments.

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.