Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
angular.module("app", [])
.service("myAwesomeService", function () {
return {
doWork: function () {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve([1, 2, 3, 4, 5])
}, 2500);
})
}
}
})
.component("myAwesomeComponent", {
template: "Counter: {{ $ctrl.counter }}",
controller: function (myAwesomeService) {
var ctrl = this;
ctrl.counter = 0;
ctrl.$onInit = function () {
myAwesomeService.doWork().then(function(result) {
ctrl.counter = result.length;
})
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment