0
votes

The code related to table generation is not working in the below function

function populateDataTable(repo_contributor,repo_langauges){
    $scope.rowCollection = [
        {firstName: 'Laurent', lastName: 'Renard', birthDate: new Date('1987-05-21'), balance: 102, email: '[email protected]'},
        {firstName: 'Blandine', lastName: 'Faivre', birthDate: new Date('1987-04-25'), balance: -2323.22, email: '[email protected]'},
        {firstName: 'Francoise', lastName: 'Frere', birthDate: new Date('1955-08-27'), balance: 42343, email: '[email protected]'}
    ];

 for (var key in repo_contributor){
    console.log(repo_contributor[key]);
    var repo_table_data = {};
    repo_table_data['repo_name'] = key; 
    repo_table_data['contributors'] = repo_contributor[key].toString();
    repo_table_data['languages'] = repo_langauges[key].toString();
     console.log(repo_table_data);
    $scope.repo_info_list.push(repo_table_data);
}
    console.log("here now");
    console.log($scope.repo_info_list.length);

}

the populateDataTable is being populated by the below code

setTimeout(populateDataTable,4000,$scope.repo_contributor,$scope.repo_languages);

$scope.rowCollection is being set but not being displayed on table( table is empty).

However if $scope.rowCollection is placed outside the populateDataTable, the table is populated with correct values.

Your help is greatly appreciated.

3
Use $timeout function for this instead of setTimeout.so inject it to controller.Hadi J
Beautiful! it worked like a charm! Thank you!Varun Mallya

3 Answers

0
votes

you have to try like this

setTimeout(function() {            
   populateDataTable($scope.repo_contributor,$scope.repo_languages);
  }, 4000)
0
votes

In setTimeOut try an arrow function like this:

setTimeout( ()=> {            
   populateDataTable($scope.repo_contributor,$scope.repo_languages);
  }, 3000)
0
votes

As mentioned by Hadi, setTimeout did not work but $timeout with function parameters worked.

i.e

$timeout(populateDataTable, 4000,true,$scope.repo_contributor,$scope.repo_languages)