I am making the following http get call to acquire an html page source code 
and then parse through it.


For some reason, it keeps returning undefined.


How can I fix it?


It seems that $http.get() is asynchronous, so how would I go about 
returning a value from it?


I have to refactor my code to use $q.defer() right? But I am not sure how 
to do this...


Code below:


function checkInventory() {



  var newReqObj = DataService.getFormData();

  var store = newReqObj.store;

  var code = newReqObj.code;

  var size = newReqObj.size;




  if(store === 'nike') {

        var inventoryData = checkNike(store, code, size);

        $log.debug(inventoryData);

        return inventoryData;

    }

}




function checkNike(store, code, size) {

    var inventoryData = {

        'qtyAvailable': 0,

        'maxOrder': 0,

        'size': 0,

        'name': '',

        'price': '',

        'url': '',

        'code': code

    };




    var url = 'http://www.nike.co.uk/search?q=' + code;

    checkNikeUrl(url, size, inventoryData);

}




function checkNikeUrl(url, size, inventoryData) {

    $http.get(url).then(function(response) {

        var html = response.data;




        inventoryData.qtyAvailable = utility.getProductQty(html, size);

        inventoryData.maxOrder = utility.getProductMaxOrder(html, size);

        inventoryData.size = size;

        inventoryData.name = utility.getProductName(html);

        inventoryData.price = utility.getProductPrice(html);

        inventoryData.url = url;




        return inventoryData;

    })



};




-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to