Angular 2 with jQuery

2

Hey guys, I was wondering if using jquery along with angular2 is recommended, or does angular already have native functions for manipulating the DOM as well as jquery?

In my case I wanted a simple task. Just change the height of a div:

var content = jQuery("#content");
var window_h = jQuery(window).height();
var top_bar_h = jQuery(".top-bar").innerHeight();
var nav_bar_h = jQuery(".nav-bar").innerHeight();

var content_h = window_h - (nav_bar_h + top_bar_h);
content.height(content_h);

is there any way I can do this using only angle2? vlw!

    
asked by anonymous 05.05.2016 / 07:49

1 answer

3

While it is the main function of the Angular manipulate the structure of the page (DOM) according to the data ( data-bindind ), it does not have in its API features for calculating visual aspects.

So basically, you are free to use any other library, including jQuery, to perform other types of operations such as manipulating certain styles, as long as you do not manipulate the document structure.

However, there is a "catch" or problem there. Manipulating styles in this way will add CSS inline in the HTML tag, so if the Angular update that element at some point, it will lose that added style manually. The solution is to calculate the height whenever you update the element or arrange another way to set the height.

    
05.05.2016 / 08:13