angular/angular.js — pull request #4377 by buunguyen (2013-10-11 03:54:26+00:00)
Title: fix($rootScope): make $digest loop works correctly with $sce trusted values

When using `$watch(..., ..., false)` to watch a `$sce` trusted value that is constructed dynamically, $digest comparison fails to recognize that while the trusted value instance may be different, the value being wrapped is the same. This results in the "10 $digest() iterations reached. Aborting!" error. A common use case is using a filter to transform HTML and wrap the result with `$sce.trustAsHtml()`. This plunker demonstrates the issue: http://plnkr.co/edit/Q04wTEgMwr7HnSsG0xVs?p=preview.

This fix modifies $digest comparison loop to use `$sce.valueOf()` to unwrap values. To save one unwrap operation per comparison, instead of invoking that method to unwrap both the current value and last values, the method is only invoked for the current value and just let the unwrapped value stored in last value.