JS Timer Event Controlling Model Properties
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Alexander Ouellet,
Is counter a ThingWorx Studio Application Parameter?
If yes; try using: $scope.app.params.counter
I hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
It is, however I got an error in the console when using .counter vs ['counter']
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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);
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Using simply .counter vs ['counter'] gave an error in the console
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
I had a similar problem, but I was able to force a view update by calling $scope.$apply().
