0

My app.component.html contains these code to display the slider.

 <div  class="slider-pro" id="slider" *ngIf="router.url == '/home'">
   <script type='text/javascript'>
      initSlider();
    </script>
   ...
 </div>

But it seem that the angular2 framework skip my javascript lines. My question is how to call a javascript function after *ngIf render DOM element. I tried call this function inside ngAfterViewInit(), but it doesn't worked. I need to run this function initSlider() to add onChange event.

1 Answer 1

1

Call this function inside ngAfterViewChecked. This gets called after every check of component's view.

class MyComponent implements AfterViewChecked {
    ngAfterViewChecked() {
        //TODO - invoke here
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks your suggestion, but if I do this, my javascript will execute n times. The on-change, or click event will execute n times as well. In addition, I have my own solution. Thanks

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.