I am new to Angular and am trying to get data from a built.io class and add it to $scope in angular. I have worked through all the beginning Egghead examples and AngularJS tutorials but haven't worked this out yet. Console shows that the json is returned but my attempts to add this json to $scope haven't been successful. I think I should be doing this with a promise and have tried several times with no luck. The basic html is:
<!doctype html>
<html ng-app="Built">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://raw.githubusercontent.com/raweng/built.io-geoquery-playground/master/js/builtio.js"></script>
<script src="builtapp.js"></script>
<link rel="stylesheet" href="bootstrap.css">
<script>
Built.initialize('blt90ca3ef1fcb6f354', 'CIC001');
</script>
</head>
<body ng-controller="MainCtrl">
<div>
<div ng-repeat="client in clients">
{{ client.get('name') }}
</div>
</div>
</body>
</html>
and the js:
angular.module('Built', [])
.controller('MainCtrl', function($scope) {
$scope.client = null;
var myQuery = new Built.Query('Client');
myQuery.exec({
onSuccess: function(data) {
// projects is array of Built.Object
// here's the object we just created
$scope.clients = data;
},
onError: function(err) {
// error occured
}
});
});
I have created a fiddle at: https://jsfiddle.net/o2oxuz12/9/
Just updated the fiddle to include an alert showing an item of data.