Boot AngularJS + Cloud Endpoints-Collection of common programming errors

Is there a way to initialize angular and endpoints without manual boot of angular?

I thought I’d found an elegant solution here.

Unfortunately for me window.init isn’t always declared before it’s called by the callback despite the sequence order of scripts. It works fine on refresh but not always on first page load. The console outputs “Uncaught TypeError: Object [object global] has no method ‘init’ “.

Finally I’ve tried to manually bootstrap angular from the endpoints callback (eg here, but on trying this it caused lag where angular should replace the handlebar placeholders, so the html was full of handlebars for a few seconds. I appreciate this may be the only way to do this however the first link above from google suggests otherwise.

UPDATE:

function customerInit(){
    angular.element(document).ready(function() {
    window.init();
     });
}

This seems to solve my problem, it enforces that angular controller is initialized before endpoints. This isn’t mentioned on googles page here, but it seems necessary to enforce the order of initialization.

hmtl:


    
        

        
        
        

    




        
            

Customers

        

        
        

                
First Name Surname Email Address Home Phone Mobile Phone Work Phone
{{customer.firstName}} {{customer.surName}} {{customer.emailAddress}} {{customer.homePhone}} {{customer.mobilePhone}} {{customer.workPhone}}

customer.js:

function customerInit(){
    window.init();
}

function customerCtrl ($scope) {

    window.init= function() {
          $scope.$apply($scope.load_customer_lib);
        };

    $scope.is_backend_ready = false;

    $scope.allCustomers = [];

    $scope.load_customer_lib = function() {
                                gapi.client.load('customer', 'v1', function() {
                                    $scope.is_backend_ready = true;
                                    $scope.getAllCustomers();
                                  }, '/_ah/api');
                                };


    $scope.getAllCustomers = function(){

        gapi.client.customer.customer.getCentreCustomers()
                                .execute(function(resp) {

                                     $scope.$apply(function () {
                                        $scope.allCustomers = resp.items;
                                     });

                                });
    };


};

Additional: $window also didn’t work for me:s

  1. This sorted out my boot sequence:

    function customerInit(){
            angular.element(document).ready(function() {
            window.init();
             });
        }
    

    The ng-cloak directive prevents me from seeing a flash of unparsed angular directives.

Originally posted 2013-12-02 01:21:08.