Closed lommez closed 7 years ago
Well that's more of an Angular How-To question.
But let's start with expected behavior of the above code.
Everytime total()
is called, .sum()
creates a new ArrayEnumerator
and walks through the array creates a sum. Then any objects that were related to that enumeration are disposed.
The key is, that the function total
is actually being called.
"Binding" to total may not be doing what you think.
When I had a changing value like you are describing, there still needed to be an event that triggered the change, or you are binding angular to an object/model that it can track changes.
You can't track changes on a function because the function doesn't change itself. Something has to 'update' the model that angular is 'watching'.
Thanks for tips.. I've implemented a 'watch' to detect changes and now is working!
Yes. That's exactly how we had to do it. But just be very careful. Watches can get out of hand. If you have to add more than 3 of them, you probably did something wrong. :P
Hi,
For example, i have an array like that:
var numbersArray = [1, 2, 3, 5, 6]; var myEnumerable = Enumerable.from(numberArray); function total(): number { return myEnumerable.sum(); }
numberArray.push(7);
In my application i'm using angular and binding the total result in the view. Is possible whenever the numbersArray suffer any modification to be updated in the view?