S
S
Sergey2014-11-21 16:54:37
JavaScript
Sergey, 2014-11-21 16:54:37

How to apply jQuery plugin on angularjs?

Can you tell me how to apply jQuery plugin on angularjs?
Directive code:

app.directive('ibaModel', function () {
    return {
        restrict: 'A',
        priority: 1010,
        link: function (scope, element, attrs) {
            // debugger;
            var el = $(element);
            el.attr('id', scope.config.templateId);
            
            el.iba_model('init', {id: scope.config.templateId});
        }
    };
});


doesn't work like that. Inside the plugin, there are requests to the server for scripts and markup.

The plugin successfully renders the code but does not fire the events.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Benkovsky, 2014-11-21
@karmis

1. Using jquery and angular is not the best idea, they have completely different ideologies. But if "you need it and that's it", then
2. Angular knows nothing about the events that took place "outside the angular world". Your

el.iba_model('init', {id: scope.config.templateId});
explicitly adds something to the DOM and for Angular to know about it You need to call $digest (or the safer $apply function) at this point
Here is an example not of my jsfiddle jsfiddle.net/tnq86/15
jquery callback $scope.$digest() is called

S
Sergey Mishin, 2014-11-21
@sergeysmishin

You have not declared a local scope

app.directive('ibaModel', function () {
    return {
        restrict: 'A',
        priority: 1010,
        scope: {
            config:{
                   templateId:'='
            }
       },
        link: function (scope, element, attrs) {
            // debugger;
            var el = $(element);
            el.attr('id', scope.config.templateId);
            
            el.iba_model('init', {id: scope.config.templateId});
        }
    };
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question