Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

AngularJS has functions which override jquery functions. For e.g., wrap() function is there in angular.js and in jquery-1.10.2 also but I want to call the wrap() function of angular.js so how should I call it?

For now, when I try to call it in my directive like this, it calls the jquery's wrap() function:

element.wrap(outerDiv);

The need of this is, wrap() function doesn't work properly if it's called from jquery. Though it wraps the elements, it doesn't give angular environment, e.g. {{ name }} does not print name property. When I removed jquery file, wrap() function of angular.js was called and it worked perfectly fine.

share|improve this question
    
Shouldn't the function do the same thing since angular is using a jquery light version –  Hatsjoem Apr 14 at 10:09
    
@Hatsjoem: Well, I also first thought that it might be some issue with wrap() function but then came to know that if I remove jquery or if somehow the function from angular.js is called instead of jquery, it works well and provides angular environment. –  Mital Pritmani Apr 14 at 10:12
    
You always use the wrap of jquery when jquery is included. That's the idea behind that. It rly should do the same! –  Fuzzyma Apr 14 at 10:16
    
Can you make a fiddle for it? –  Hatsjoem Apr 14 at 10:20
add comment

2 Answers

The angular js function .wrap() is the same as the jQuery function .wrap().

Quoted from the docs:

If jQuery is available, angular.element is an alias for the jQuery function. If jQuery is not available, angular.element delegates to Angular's built-in subset of jQuery, called "jQuery lite" or "jqLite."
source

So meaning if you have jQuery included, the angular js function wrap() will be an alias for the jQuery function wrap else it will be jqLites .wrap() (which is the same).

share|improve this answer
    
I also thought so but seems this is a bug. Because once I remove jquery, it works fine. But when jquery is present, it doesn't print the model values in the div tag which is a wrapping element. Try it, wrap an input element with some div and print the model value in div, it would print {{ name }} only instead of the actual value of name. –  Mital Pritmani Apr 15 at 4:24
add comment

If you want to avoid reading up too much you could use the jquery functions which take the element as parameter instead of the methods prototyped onto the jQuery object.

Then again one might look at this as a workaround.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.