jQuery $(document).ready () fires twice

前端 未结 13 880
忘了有多久
忘了有多久 2020-11-29 03:13

I\'ve been sifting around the web trying to find out whats going on here and I have not been able to get a concrete answer.

I have one $(document).ready

13条回答
  •  攒了一身酷
    2020-11-29 03:37

    There is a possibility to encounter this problem when you add same controller twice in the html.
    For an instance:
    [js]

    app.controller('AppCtrl', function ($scope) {
     $(document).ready(function () {
            alert("Hello");
            //this will call twice 
        });
    });
    

    [html]

    //controller mentioned for the first time
    
        //some thing
    
    
    //same controller mentioned again 
    
        //some thing
    
    

提交回复
热议问题