AngularJS doesn't load on first run

272 views
Skip to first unread message

Xerses

unread,
Oct 18, 2016, 8:35:27 AM10/18/16
to Angular
Hi everyone,

I work with AngularJS only recently and came over a strange behaviour with it.
I'm working on local server with WAMP and when I load my website the first time on any browser (Chrome, Firefox, IE), it seems AngularJS doesn't load because none of my ng-repeat nore angular variables are executed.

But If I reload the page (F5), it works like a charm and all the pages of the website work.
Also, if I close my browser and re-open it, it works.

Another point, if I restart the services of WAMP, the problem appears again.
And finally what is very strange is that : 
 - if I open the site a first time on Chrome (for ex.) > it bugs ; if I then open it on Firefox > it works
 - I restart the services on WAMP
 - if I open the site a first time on Firefox > it bugs ; if I then open it on Chrome > it works

It seems the first time I open it on any browser, something is happening in wamp config and the next time it will work.
But I want it to work on the first load ! :)

Here is the bug report I have on the first load :

Here is how I create the AngularJS app :
var briefuniqueApp = angular.module('BriefUnique', ['ngRoute','angular-szn-autocomplete']);

briefuniqueApp.config(['$routeProvider',
    function($routeProvider) { 
        // Système de routage
        $routeProvider
        .when('/accueil', {
            templateUrl: 'pages/accueil.html',
            controller: 'accueilCtrl'
        })
        .when('/newsurvey', {
            templateUrl: 'pages/newsurvey.html',
            controller: 'newsurveyCtrl'
        })
        .when('/project/:projectId', {
            templateUrl: 'pages/project.html',
            controller: 'projectCtrl'
        })
        .when('/brief/:briefId', {
            templateUrl: 'pages/brief.html',
            controller: 'briefCtrl'
        })
        .when('/fieldwork/:briefId', {
            templateUrl: 'pages/fieldwork.html',
            controller: 'fieldworkCtrl'
        })
        .when('/testmaterial/:briefId', {
            templateUrl: 'pages/testmaterial.html',
            controller: 'testmaterialCtrl'
        })
        .otherwise({
            redirectTo: '/accueil'
        });
    }
]).run(['$rootScope', '$location', '$http', function($rootScope, $location, $http){

    /* Global Variables */
    $rootScope.ResearchSelected = false;
    $rootScope.BriefSelected = false;
    $rootScope.NbSelectedCountries = 0;

}]);

Here is how I load the javascript files :
<script src="js/jquery-3.1.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
    <script src="js/angular.min.js"></script>
    <script src="js/angular-route.min.js"></script>
    <script src="js/angular-szn-autocomplete.js"></script>
    <script src="js/bootstrap-select.js"></script>
    <script src="js/bootbox.min.js"></script>
    <script src="js/bootstrap-toggle.min.js"></script>
    <script src="js/jquery.stickytableheaders.min.js"></script>

    <script src="js/fixed-issues.js"></script>

    <script src="app/BriefUniqueApp.js"></script>
    <script src="app/Controllers_Accueil.js"></script>
    <script src="app/Controllers_NewSurvey.js"></script>
    <script src="app/Controllers_Brief.js"></script>
    <script src="app/Controllers_Project.js"></script>
    <script src="app/Controllers_Fieldwork.js"></script>
    <script src="app/Controllers_TestMaterial.js"></script>


Is there anyone who had this problem ?

Thanks for your help.
Best regards

Xerses

unread,
Oct 19, 2016, 2:54:32 AM10/19/16
to Angular
Okay ! I find the solution !
In fact, it was a problem with $http request that make WAMP show a message about deprecated function. Because this message only appears the first time you load a website, it disapears the next time and that's why it works.
So, I just had to change my $http post with some new header and now it works everytime !
Reply all
Reply to author
Forward
0 new messages