Answer the question
In order to leave comments, you need to log in
How to pass a function to a custom directive from a controller?
There is a custom directive for which you need to do ng-change. But only function (a) {h(c, a) comes to the directive controller. That is, my function is lost somewhere along the way.
Sample
input(
ng-model="dt"
ng-change='onChange'
)
.directive('uiDatepicker', [()->
obj =
restrict: 'AE'
replace: true
templateUrl: '/partials/datepicker'
scope:
dt: '='
onChange: '&'
controller: ['$scope', ($scope)->
console.log $scope.onChange #function (a) {h(c, a)
]
obj
])
ui-datepicker(dt='tenancy.startDate', onChange='test()')
Answer the question
In order to leave comments, you need to log in
For starters, you have the wrong attribute name
If you want to pass exactly the same function that was set in the controller, then you have chosen the wrong binding mechanism. You need pass by value, not by expression so use pass by value in your isolated scope
.directive('uiDatepicker', [()->
...
scope:
dt: '='
onChange: '='
])
ui-datepicker(dt='tenancy.startDate', on-сhange='test')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question