Angular 2 how to enable default/native setTimeout method instead of Angular2 patched version of setTimeout.

1,756 views
Skip to first unread message

Dmitrii Rogozin

unread,
Apr 13, 2016, 7:24:19 AM4/13/16
to AngularJS
The original problem is the following, we have a component which has a lot of setTimeout/setInterval calls, to represent UI changes. We want to integrate this component into Angular2. The problem is
that if someone implements DoCheck interface, ngDoCheck() method is called on every setTimeout in the whole application. Can we disable/tweak it somehow. Basically what we want is to have a default implementation
of setTimeout for our own component.
Honestly the idea of rewriting system functions, in your framework doesn't seem to be a good idea, so I assume there is some native approach to disable ti.

Sander Elias

unread,
Apr 13, 2016, 8:35:19 AM4/13/16
to AngularJS
Hi Dmitrii,

You should run your component outside the zone. Pascal has written a nice article about that.

What you call rewrites of system functions is not as much a rewrite, as it is a way to place the needed(and currently missing) hooks into the system. What you call a rewrite is actually (probably) going to make its way into JS itself. 

Regards
Sander

Dmitrii Rogozin

unread,
Apr 13, 2016, 11:16:44 AM4/13/16
to ang...@googlegroups.com
Hello, Sander, thank you for your reply.

I guess you mean something like this?

  constructor(private zone: NgZone) {
    this.zone.runOutsideAngular(()=>{  
        component = OwnLibrary.createOwnComponent();
        component.renderTo("Div ID from Angular2 template");
     });
 } 

It doesn't completely fit our case, but we get some inspiration from your answer. Thank you!

Best regards,
Rogozin Dmitrii

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/jYWdRhzRzVQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages