How to run a jquery function in Angular 2 after every component finish loading

You will want to use the “ngAfterViewInit” lifecycle hook, through importing AfterViewInit (https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html#!#afterview). You can use it as shown below: Installation: tsd install jquery –save or typings install dt~jquery –global –save Utilization: import { Component, AfterViewInit } from ‘@angular/core’; import * as $ from ‘jquery’; ngAfterViewInit() { this.doJqueryLoad(); this.doClassicLoad(); $(this.el.nativeElement) .chosen() .on(‘change’, (e, args) => … Read more

jQuery mobile $(document).ready equivalent

I spent some time on researching the same since JQM docs are not very detailed at this point. Solution below works fine for me: <script type=”text/javascript”> $(‘div:jqmData(role=”page”)’).live(‘pagebeforeshow’,function(){ // code to execute on each page change }); </script> You have to implement your own checking flow in order to prevent multiple initialization since the code above … Read more

Does AJAX loaded content get a “document.ready”?

To answer your question: No, document.ready will not fire again once a ajax request is completed. (The content in the ajax is loaded into your document, so there isn’t a second document for the ajax content). To solve your problem just add the event listener to the Element where you load the ajax content into … Read more

How can I run a directive after the dom has finished rendering?

It depends on how your $(‘site-header’) is constructed. You can try to use $timeout with 0 delay. Something like: return function(scope, element, attrs) { $timeout(function(){ $(‘.main’).height( $(‘.site-header’).height() – $(‘.site-footer’).height() ); }); } Explanations how it works: one, two. Don’t forget to inject $timeout in your directive: .directive(‘sticky’, function($timeout)

Is $(document).ready necessary?

Is $(document).ready necessary? no if you’ve placed all your scripts right before the </body> closing tag, you’ve done the exact same thing. Additionally, if the script doesn’t need to access the DOM, it won’t matter where it’s loaded beyond possible dependencies on other scripts. For many CMS’s, you don’t have much choice of where the … Read more