Angular Js Object:
$scope.Global = {
brand: null,
group: null,
timeperiod: null,
gender: $scope.Gender[0],
segmenttype: $scope.SegmentType[0]
};
Angular Js Service method:
dataFactory.getAllTimePeriods().success($scope.handleSuccess).then(function (result) {
$scope.TimePeriods = result.data;
});
is it possible that we can call service method to object property?
like this
$scope.Global = {
brand: null,
group: null,
timeperiod: dataFactory.getAllTimePeriods().success($scope.handleSuccess).then(function (result) {
$scope.TimePeriods = result.data;
});,
gender: $scope.Gender[0],
segmenttype: $scope.SegmentType[0]
};
As Liad Livnat said you could write
dataFactory.getAllTimePeriods().success($scope.handleSuccess).then(function (result) {
$scope.Global = {
brand: null,
group: null,
timeperiod: result.data;
gender: $scope.Gender[0],
segmenttype: $scope.SegmentType[0]
};
}
If you have multiple promises you can use $q.all like this
var promiseOne = dataFactory.getAllTimePeriods().success($scope.handleSuccess);
var promiseTwo = ...
var promiseThree = ...
$q.all([promiseOne, promiseTwo, promiseThree])
.then(function(results) {
$scope.Global = {
brand: null,
group: null,
timeperiod: results[0].data;
gender: $scope.Gender[0],
segmenttype: $scope.SegmentType[0]
};
console.log(results[0], results[1], results[2]);
});
As you can see the results variable gets all the data from the promises in an array and you can access them using results[0], results[1], and so on.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句