I am using AngularJs of $http
function, I have one async function need the other one to feedback variable and then to continue ,My code is as follows:
function getDataList(company_id) {
return $http.get("https://for_test_document/restful_api/brandsearch/format=json&company_id=" + company_id);
}
then I try to use it as follows, the JSON has been received correctly:
for (var i = 0; i < len; i++) {
getDataList(json.data[i].id).then(function(successdata) {
var len = successdata.data.length;
var brand_name = "";
for (var j = 0; j < len; j++) {
brand_name = brand_name + successdata.data[j].Brand_Name + '/';
}
console.log(brand_name);
return brand_name + ""
})
My question is that, the console.log
have show what the brand_name
correctly, however why in the Browser it shows object?
my html is as follows:
function loadInfo(){
$http({
method:'GET',
url:'https://for_example/restful_api/companysearch/?format=json',
dataType: "json",
contentType : 'application/json',
Accept: 'application/json',
}).then(function (json){
get_company_type().then(function (data) {
unique_company_type = data.data
})
/*insert data to table */
var len =json.data.length;
var tableStr = '';
tableStr = tableStr+ content
tableStr = tableStr+'<tbody role="alert" aria-live="polite" aria-relevant="all">';
for(var i=0;i<len;i++){
tableStr = tableStr+'<td class=" ">' +
getDataList(json.data[i].id).then(function (successdata){
var len = successdata.data.length;
var brand_name = "" ;
for(var j=0;j<len;j++){
brand_name = brand_name +successdata.data[j].Brand_Name+'/';
}
console.log(brand_name);
return brand_name + "" }) +
'</td><td class=" ">' +json.data[i].City + '</td><td class=" ">' +json.data[i].Address + '</td><td class=" ">' +'Client Contact' +
'</td><td class=" ">' + 'Contact details' + "</td></tr>";
}
tableStr = tableStr+"</tbody>";
Thanks for any helps.