0

I am very new to Angular4 hence this question may be really stupid. I am trying to do a seemingly very simple thing but it has been very difficult with angular. I am trying to run a JQuery code which is located main.js file after the HTML is rendered by Angular.

I have been trying this for some days, but nothing works, please help!

  • Posiible duplicate of: https://stackoverflow.com/questions/35728731/how-to-run-a-jquery-function-in-angular-2-after-every-component-finish-loading – Md Hasan Ibrahim Jun 22 '17 at 09:57

1 Answers1

0

Angular offers many life-cycle events:

https://angular.io/guide/lifecycle-hooks

You are probably looking for the AfterViewInit event.

import { AfterViewInit } from '@angular/core';

export class MyComponent implements AfterViewInit {
  ngAfterViewInit(){
    // do your things here
  }
}
Ploppy
  • 14,810
  • 6
  • 41
  • 58
  • can i invoke my custom methods defined in main.js file using AfterViewInit event? if yes, how? – Kgothatso Mathbatha Jun 22 '17 at 10:43
  • Well it's hard to tell. Assuming your are using angular-cli (which I recommend you to do) there is `scripts` array in the `.angular-cli.json` where you can import .js files and acces them anywhere in your project. – Ploppy Jun 22 '17 at 10:57