2

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.

4
  • Shouldn't the function do the same thing since angular is using a jquery light version Commented Apr 14, 2014 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. Commented Apr 14, 2014 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! Commented Apr 14, 2014 at 10:16
  • Can you make a fiddle for it? Commented Apr 14, 2014 at 10:20

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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.

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.