I wonder what is the most elegant way to initialize/the objects that I fill from the AJAX call and are used 'concurrently' somewhere in a directive.
I have a controller with such snippet:
$scope.var1 = {};
$scope.var2 = {};
$http({
url: "/httpService",
method: "GET",
params: {}
}).success(function(data, status) {
$scope.var1 = data.some; // (*1)
$scope.var2 = data.other;
})
I am also using a directive which binds directly to var1:
var1 : '='
and inside the directive there is some check on var1.
if (var1.prop) // (*2) {
doSth();
}
Depending on which of (*1), (*2) gets called first, the outcome is different.
What is your advice for this case? In case I would only have one variable set at (*1) I would just use the promise got as a result of $http.
I wonder what's the most idiomatic way to do it in Angular. Combining var1 and var2 into one object seems not elegant to me.