Following this question I've run into another 'issue'.
Basically I've got a HTML theme that has a lot of initialising code ($document.ready()
code) that I need to run in ngAfterViewInit
. My issue is that this doesn't work when I put it in my app.ts file (the root app component), so I'm having to put it all into every single component I create, which doesn't seem right.
I wonder if I'm missing something obvious or if the app component instantiates before the rest of the component loads?
app.ts
import {Component, ViewEncapsulation, AfterViewInit} from 'angular2/core';
export class AppCmp implements AfterViewInit {
ngAfterViewInit() {
//All my document ready code here, which doesn't work
}
}
EDIT I will try and be a bit more specific.
The code in question can be seen here. It is basically all the code that instantiates and runs my modals, parallax, dropdowns etc. etc. I.e. all javascript that needs to run after angular has initialised the view and called it's ngAfterViewInit
. If I copy paste all the code into ngAfterViewInit
in my app.ts
, then nothing will work, modals, parallax, accordions etc. But if I put the same code into a specific components (e.g. home.ts
) then it works just fine. Hope this clarifies.
Say I wanted to run the following when the page was fully loaded:
setTimeout(function() {
$('.background-image-holder').each(function() {
$(this).addClass('fadeIn');
});
}, 200);
In app.ts this fails to run, but in home.ts this runs just fine