how to call service method from object property in angularjs?

Samir Shah

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]
};
Edminsson

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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Call private method of object from callback

来自分类Dev

How to call a varargs method with an additional argument from a varargs method

来自分类Dev

how to call the web method only when '/' is the last character from autocomplete?

来自分类Dev

Swift: How to call a category or class method from Objective-C

来自分类Dev

Call Web Service from xquery

来自分类Dev

How to call method within builder

来自分类Dev

How to call Twig extension filter or function from PHP (controller / service / other twig extension etc )?

来自分类Dev

Generate Routes in .run() with config from service Angularjs

来自分类Dev

Call method in different class from click event method in c#

来自分类Dev

accessing the parent object from the child object property in javascript

来自分类Dev

Java generic method - how to make it call a specialized method

来自分类Dev

Invoking operator[] method from within object

来自分类Dev

Undefined method `name' for nil:NilClass for a property from a joined table

来自分类Dev

SSIS Not Detecting Input Service or Method from WSDL File

来自分类Dev

How to change the volume using adb shell service call audio

来自分类Dev

Call derived class method from base class instance

来自分类Dev

How to read specifications from a REST Web Service

来自分类Dev

Asynchronous WCF service call

来自分类Dev

ScalaMock: How to mock/stub a method to return different values per call?

来自分类Dev

an object reference is required for non static field method or property MyApplication.MyApplicationBl.TeamService.GetTeams()

来自分类Dev

How to pass the object property as param to struts custom validator

来自分类Dev

DART : how can assign the result of httpRequest on a property object?

来自分类Dev

How to serialize anonymous object to JSON without including property name

来自分类Dev

How to insert elements in DART Polymer template based on object property condition?

来自分类Dev

How to get all values of specific nested property in JS object

来自分类Dev

How to break from the blocking TcpListener::accept call?

来自分类Dev

AngularJS controller and service creation

来自分类Dev

How to close bootstrap modal window from angularjs

来自分类Dev

PL/SQL How to call a function without getting returned object

Related 相关文章

  1. 1

    Call private method of object from callback

  2. 2

    How to call a varargs method with an additional argument from a varargs method

  3. 3

    how to call the web method only when '/' is the last character from autocomplete?

  4. 4

    Swift: How to call a category or class method from Objective-C

  5. 5

    Call Web Service from xquery

  6. 6

    How to call method within builder

  7. 7

    How to call Twig extension filter or function from PHP (controller / service / other twig extension etc )?

  8. 8

    Generate Routes in .run() with config from service Angularjs

  9. 9

    Call method in different class from click event method in c#

  10. 10

    accessing the parent object from the child object property in javascript

  11. 11

    Java generic method - how to make it call a specialized method

  12. 12

    Invoking operator[] method from within object

  13. 13

    Undefined method `name' for nil:NilClass for a property from a joined table

  14. 14

    SSIS Not Detecting Input Service or Method from WSDL File

  15. 15

    How to change the volume using adb shell service call audio

  16. 16

    Call derived class method from base class instance

  17. 17

    How to read specifications from a REST Web Service

  18. 18

    Asynchronous WCF service call

  19. 19

    ScalaMock: How to mock/stub a method to return different values per call?

  20. 20

    an object reference is required for non static field method or property MyApplication.MyApplicationBl.TeamService.GetTeams()

  21. 21

    How to pass the object property as param to struts custom validator

  22. 22

    DART : how can assign the result of httpRequest on a property object?

  23. 23

    How to serialize anonymous object to JSON without including property name

  24. 24

    How to insert elements in DART Polymer template based on object property condition?

  25. 25

    How to get all values of specific nested property in JS object

  26. 26

    How to break from the blocking TcpListener::accept call?

  27. 27

    AngularJS controller and service creation

  28. 28

    How to close bootstrap modal window from angularjs

  29. 29

    PL/SQL How to call a function without getting returned object

热门标签

归档