Angular2 equivalent of $document.ready()

前端 未结 6 993
清歌不尽
清歌不尽 2020-12-01 03:48

Simple question, I hope.

I want to run a script when the Angular2 equivalent of $document.ready() is fired. What is the best way to achieve this?

I\'ve tried

6条回答
  •  醉梦人生
    2020-12-01 04:29

    Copying the answer from Chris:

    Got it working:

    import {AfterViewInit} from 'angular2/core';    
    
    export class HomeCmp implements AfterViewInit {    
    
        ngAfterViewInit() {
           //Copy in all the js code from the script.js. Typescript will complain but it works just fine
        }
    

提交回复
热议问题