A simple question, I hope.
I want to run a script when Angular2 is equivalent to $ document.ready (). What is the best way to achieve this?
I tried putting the script at the end of index.html , but as I found out, this will not work! I suppose it should be in some kind of component declaration?
Is it possible to start script loading from a .js file?
EDIT - Code:
I have the following js and css plugins introduced into my application (from the Foundry html theme ).
<link href="css/themify-icons.css" rel="stylesheet" type="text/css" media="all" /> <link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" /> ... <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/flexslider.min.js"></script> ... <script src="js/scripts.js"></script> //This initiates all the plugins
As already noted, scripts.js "launches" all of this and therefore needs to be run after Angular is ready. script.js
It worked:
import {Component, AfterViewInit} from 'angular2/core'; @Component({ selector: 'home', templateUrl: './components/home/home.html' }) export class HomeCmp implements AfterViewInit { ngAfterViewInit() {
angular
Chris Dec 31 '15 at 13:23 2015-12-31 13:23
source share