How to apply jquery after AngularJS partial template is loaded

后端 未结 7 2365
青春惊慌失措
青春惊慌失措 2020-12-13 10:28

I have a simple website that implements jQuery in order to create a Slider with some images in the Index.html top banner.

Now, I want to use AngularJS

7条回答
  •  不思量自难忘°
    2020-12-13 11:04

    I had the same problem, I was loading some nav links in a ng-include and I have a script file called on my index.html with jquery instructions to make links active and It i not see the included content.

    I tried all of the above solutions and for some reasons, none of them worked for me. When the content is not included (straight in the index.html) jquery kicks in fine but once included it stopped recognizing my elements.

    So I simply wrapped my instructions in a setTimeout() function and it worked! Maybe it'll work for you too?

    setTimeout(function() {
        $("nav ul li").click(function() {
            $("nav ul li").removeClass('active');
            $(this).addClass('active');
        });
    });
    

    Somehow the setTimeout() manages to load the script AFTER angular is done loading included content.

    Happy coding everyone !

提交回复
热议问题