angular2-polyfill icon indicating copy to clipboard operation
angular2-polyfill copied to clipboard

Create shims for `setTimeout`, `Promise`, `setInterval`, ...

Open SamVerschueren opened this issue 8 years ago • 1 comments

In Angular1, you would have to $scope.$apply when using setTimeout, setInterval, etc. This is not necessary anymore in Angular2 because the entire change detection changed.

In order for easier migration later on, it might be nice to provide shims for this.

import {setTimeout, setInterval} from 'angular2-polyfill/ng2-shims`;

Where setTimeout basically is an alias for $timeout.

Benefit

When migrating to Angular2, you would only have to remove the imports at the top and nothing else changes.

List of shims

  • window$window
  • setTimeout$timeout
  • setInterval$interval
  • Promise$q (tweaked version of $q to make it more Promise compatible)

SamVerschueren avatar Feb 25 '16 13:02 SamVerschueren

@jvandemo suggested to work with zone.js in order to apply the root scope when the async task is executed. Probably with the afterTask hook. Not sure though, not a zone expert :).

SamVerschueren avatar Mar 03 '16 18:03 SamVerschueren