cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

JS Timer Event Controlling Model Properties

Highlighted
Regular Member

JS Timer Event Controlling Model Properties

I am attempting to use a simple JS timer function to write values to a variable, which is then bound to the model property "ry"

The idea being, I can click a button to call the function, the the model continuously rotates until the function is cleared.

I created the "counter" parameter and bound it to the "ry" property, as well as defining the click events as their respective functions.

However, the dev console shows that the value is not being stored in "counter" and is not showing as bound to "ry."

My code looks like the below:

$scope.set_timer = function(){

  $scope.app.params['counter'] = 0 ;

  $scope.app.params.time=setInterval(function(){

    $scope.app.params['counter'] ++;

    console.log(counter);

  }

  , 1000);

}

$scope.stop_time = function(){

  $scope.app.params.time = clearInterval(time);

}

---------------------------------------------------------------------------------------------------------

Any help is greatly appreciated.

Tags (1)
8 REPLIES 8

Re: JS Timer Event Controlling Model Properties

Hi Alexander Ouellet​,

Is counter a ThingWorx Studio Application Parameter?

If yes; try using: $scope.app.params.counter


​I hope it helps.

Re: JS Timer Event Controlling Model Properties

In your code, to access the application parameter you don't need to put the variable in the square bracket. use $scope.app.params.counter =0;

I was using the below code:

$scope.start = function(){

  $scope.app.params.counter = 0;

  $scope.countdown = function(){

  $scope.app.params.counter++;

   };

  $scope.intervalPromise = $interval($scope.countdown, 1000, 10);

};

Re: JS Timer Event Controlling Model Properties

It is, however I got an error in the console when using .counter vs ['counter']

Re: JS Timer Event Controlling Model Properties

Using simply .counter vs ['counter'] gave an error in the console

Re: JS Timer Event Controlling Model Properties

Updates:

The function does appear to write to the ry property, but only if I click the model. Any idea why I would have to click to initiate the property update?

Additionally, the values of "counter' still do not appear to be stored in the console, despite clearly being updated. Any thoughts on why that might be?

Re: JS Timer Event Controlling Model Properties

Alexander Ouellet​,

On what event are you calling your function?

I have a project where I am updating Application parameters on load of 3D model and it is working fine.

Re: JS Timer Event Controlling Model Properties

I call the function on a button event.

However, the model doesn't actually update via the parameter unless it is clicked on. i.e. the function is writing the parameter bound to ry, but the model doesn't change to represent those updates unless clicked on.

Re: JS Timer Event Controlling Model Properties

I had a similar problem, but I was able to force a view update by calling $scope.$apply().