P
P
Pavel2016-03-16 09:44:13
JavaScript
Pavel, 2016-03-16 09:44:13

Angular JS: How to describe a callback directive to be used on a single element?

The essence of the question is how to make a directive, like ng-click or ng-change, but without using an isolated scope.
Let's say there are 2 directives: onEvent1 onEvent2, these 2 events are associated with the element and callbacks are passed to them: ....
The easiest way to call these callbacks is to describe the directives using scope { handler: '&onEvent1' }:

...
.directive('onEvent1', function () {
    return {
        restrict: 'A',
        scope: { handler: '&onEvent1' },
        link: function (scope, e, a) {
              e.bind('нужное событие', function () { scope.handler(); });
        }
    };
}

but in this case, Angular swears very rudely.
As an option - do not create an isolated scope, but then the problem arises: how and with what to get the necessary callable-object from "clbk (attrs)" in the nuller, when called, the desired function will work with the parameters passed to it ?.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2016-03-16
@Padreramnt

You can take an attribute from attrs and compile it, something like:
$parse(attrs.onEvent1)($scope);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question