Angularjs ngresource getting peoblems for promise and resolve

I have a controller and there I call a service.

  var rowCollection=[];
        allCars.car('getAllcarList').getAllcarList({}).$promise.then(function(data) {
     rowCollection.push(data.cars);

      });
console.log(rowCollection);

After the service call If i want to use the rowCollection it shows undefined as the response till not come.How to stop execution until response come. So that the variable can use any where in the program.
In my service I have code like this

function($resource) {
    var apiResourceUrl='http://127.0.0.1/stock/api/public/index.php/';

    var factory = {};

    factory.allCars= function(queryType)
    {
        var hsRESTUri = apiResourceUrl;

        if (queryType == 'getAllcarList') {
            hsRESTUri = apiResourceUrl + 'getAllcarList';
        }
        return $resource(hsRESTUri, {}, {
            getAllcarList: {
                method: 'GET',
            }
        });
    };
    return factory;

Source: AngularJS



from Angular Questions https://angularquestions.com/2017/10/21/angularjs-ngresource-getting-peoblems-for-promise-and-resolve/
via @lzomedia #developer #freelance #web #lzomedia.com

Comments

Popular posts from this blog

ng-include of inline SVG does not display gradient except in Chrome

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development

ng-show doesn’t work correct with value boolean