Array push() method

Hi all

I have below JS to generate dims array:

	var dims = [];
	var dim1 = new Object();

	$tm1Ui.cellGet('FileUpload','Sys Upload Specification Page Definition','CAPEX','0001','SUBNM:Label').then(function(returnedData){
		 dim1['display'] = returnedData.Value;
    });	
	$tm1Ui.cellGet('FileUpload','Sys Upload Specification Page Definition','CAPEX','0001','SUBNM:Dimension').then(function(returnedData){
		 dim1['title'] = returnedData.Value;
    });	
	dims.push(dim1);
	

	var dim2 = new Object();
	$tm1Ui.cellGet('FileUpload','Sys Upload Specification Page Definition','CAPEX','0002','SUBNM:Label').then(function(returnedData){
		 dim2['display'] = returnedData.Value;
    });	
	$tm1Ui.cellGet('FileUpload','Sys Upload Specification Page Definition','CAPEX','0002','SUBNM:Dimension').then(function(returnedData){
		 dim2['title'] = returnedData.Value;
    });
	dims.push(dim2);
	console.log(dims)

I can get array on my console:

But i don’t get anything writing below HTML, what am i doing wrong?

<div ng-repeat="item in dims">
        {{item}}
</div>

Thanks
Tina

Hi @twu,

First, take note that the $tm1Ui.cellGet() are all executing asynchronously. Meaning, it will not wait for the previous cellGet to finish before it executes the next line of script.

Second would be, the dims from the above was declared as a non-Angular variable and is not usually accessible like that. You would normally tie them up to a $scope.


Paul

Hi @plim

Thanks.
I tried adding $scope. to dims, but that i got error on console and breaks my page,
do you have any sample how to create a new array in Angular and push element to it?

Hi @twu,

Could you post your updated code here?


Paul

Instead of var dims=[];
use $scope.dims=[];
Push objects into $scope.dims

Hi @aeremenko

Thanks changing all the dims to $scope.dims works.