Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import zone #106

Closed
chriscurnow opened this issue Oct 22, 2015 · 2 comments
Closed

How to import zone #106

chriscurnow opened this issue Oct 22, 2015 · 2 comments

Comments

@chriscurnow
Copy link
Contributor

I'm having a problem with ac-autosuggest.ts.

First off its got the same problem with rx which I know how to fix.

Second though is it tells me "zone" is unknown. I assume this means I need to import zone somehow.

Looking through the various components I can see there is an NgZone in Angular 2.

So I tried changing line 4 to read

import {Directive, View, EventEmitter, ElementRef, NgZone as zone} from 'angular2/angular2';

However at runtime, I got into an infinite loop with zone.

I'm not sure where to go from here.

If you could give me a pointer, I'm happy to make the changes and submit a pull request.

@dotcs
Copy link
Contributor

dotcs commented Oct 23, 2015

I have had a closer look to the problem. The zone object seems available already, which is why you don't need to import it. You just need to make sure, that it Typescript knows the type of the zone variable. This can be done with

declare var zone: Zone;

You can then use it as normal, e.g. in the component

onInit() {
  zone.fork({}).run(() => {
    console.log('I am running inside a zone');
  });
  // other code ...
}

See also my PR #107 which fixes the rx-autosuggest example.

@chriscurnow
Copy link
Contributor Author

Thanks. That works!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants