SamVerschueren / angular2-polyfill

Angular2 polyfill for Angular1
MIT License
29 stars 3 forks source link

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

Open SamVerschueren opened 8 years ago

SamVerschueren commented 8 years ago

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

SamVerschueren commented 8 years ago

@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 :).