function Widget1DataService($q, $http) {
var dataPromise;
this.getData = getData;
function getData(date) {
if (dataPromise) return dataPromise;
dataPromise = $q.all([
$http.post("/products/count/today", date),
$http.post("/out/today", date)
]).then(function(response) {
return {
data1: response[0],
data2: response[1]
};
});
return dataPromise;
}
}
Widget1DataService.getData(...)
.then(function(data) {
$scope.widgetData = data;
});
код после функции начинает выполнятся еще до окончания кода в onBefore
// Вариант с callback-функцией
function onBefore(completed) {
setTimeout(completed, 1000);
}
function onAfter(completed) {
setTimeout(completed, 2000);
}
// ...
onBefore(function() {
remove(id);
$element.remove();
onAfter(function() {
renderItems();
});
});
var resolveImmediately =Promise.resolve.bind(Promise);
// ...
(onBefore || resolveImmediately)()
.then(function() {
remove(id);
$element.remove();
})
.then(onAfter || resolveImmediately)
.then(function() {
renderItems();
});
class Hero {
...
public alterEgo?: string;
constructor(..., _alterEgo?: string) {
this.alterEgo = _alterEgo;
}
}
/**
*
* @param $element
* @param {ClientService} ClientService
*/
constructor($element, ClientService) {
$element.on('click', () => {
ClientService.getClientsList().then((clients)=> {
console.log(clients);
})
});
}