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:
<html ng-app lang="en">
<head>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="js/customer.js"></script>
<script src="https://apis.google.com/js/client.js?onload=customerInit"></script>
</head>
<body>
<div class="container" ng-controller="customerCtrl">
<div class="page-header">
<h1>Customers</h1>
</div>
<div class="row">
<div class="col-lg-10">
<table id="customerTable" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Surname</th>
<th>Email Address</th>
<th>Home Phone</th>
<th>Mobile Phone</th>
<th>Work Phone</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="customer in allCustomers">
<td>{{customer.firstName}}</td>
<td>{{customer.surName}}</td>
<td>{{customer.emailAddress}}</td>
<td>{{customer.homePhone}}</td>
<td>{{customer.mobilePhone}}</td>
<td>{{customer.workPhone}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/js/bootstrap.min.js"></script>
</body>
</html>
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;
});
});
};
};