0

I have an Angular2 component that has a template which requires a JavaScript calls to load it's html component, Ex. Facebook, Google Maps and some custom scripts.

The scripts are already loaded in the index.html and i just need to call them to update it's contents.

How do i call my javascript methods in angular2 when the view is changed again.

Code Example;

myJavaScript.js

loadData(){
...
}
$(document).load(loadData());

now i want to call my loadData() everytime the router views my component again.

4
  • Did you tried using ngOnInit() function for the same. Commented Jul 25, 2016 at 12:10
  • @ArpitAgarwal but how do i use my javascript method inside it? the compiler won't allow it. Commented Jul 25, 2016 at 12:13
  • On top of ya file try declare function foo();///js function. I assume your js function is available as global object. Now call that function foo in in ngOnInit() Commented Jul 25, 2016 at 12:17
  • @ArpitAgarwal please put that as an answer so i can select it! Thanks Commented Jul 25, 2016 at 12:25

1 Answer 1

1

On top of your file declare function foo();///js function It assume your js function is available as global object. Now call that function foo in in ngOnInit() lifecycle of your component

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.