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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

JS Timer Event Controlling Model Properties

aouellet
10-Marble

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.

8 REPLIES 8
ankigupta
12-Amethyst
(To:aouellet)

Hi Alexander Ouellet​,

Is counter a ThingWorx Studio Application Parameter?

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


​I hope it helps.

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

katte
12-Amethyst
(To:aouellet)

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);

};

aouellet
10-Marble
(To:katte)

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

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?

ankigupta
12-Amethyst
(To:aouellet)

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.

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.

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

Announcements

Top Tags