Skip to content

Instantly share code, notes, and snippets.

@iainplimmer
Created March 16, 2017 23:27
Show Gist options
  • Select an option

  • Save iainplimmer/b086f0317eb3ad4177b3b372c4712335 to your computer and use it in GitHub Desktop.

Select an option

Save iainplimmer/b086f0317eb3ad4177b3b372c4712335 to your computer and use it in GitHub Desktop.
<html ng-app="myApp">
<head>
<script src="./node_modules/angular/angular.min.js"></script>
<script>
angular.module('myApp', [])
.controller('cont', function ($scope) {
var vm = this;
var p1 = new Promise(function executePromise (resolve) {
resolve([{id:1, name: 'Iain'},{id:2, name: 'Erin'},{id:32, name: 'William'}]);
});
var p2 = new Promise(function executePromise (resolve) {
resolve({id:66, name: 'Sara'});
});
var p3 = new Promise(function executePromise (resolve) {
resolve({id:22, name: 'Jeremy'});
});
// Wait until all promises have been resolved
Promise.all([p1, p3, p2]).then(function (values) {
// Flatten down the array
var flattened = values.reduce(
function(a, b) {
return a.concat(b);
},
[]
);
$scope.$apply(function () {
vm.items = flattened;
});
});
})
</script>
</head>
<body ng-controller="cont as vm">
<div ng-repeat="n in vm.items">
{{n.name}}!
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment