Search code examples
angularasp.net-coresystemjs

How do I include zone.js in an angular2 app?


I don't use webpack or browserify. I use systemjs to load modules. I have the following configuration in my ASP.NET core & Angular2 application.

  1. Should I loaded zone.js globally in the app through script tag as shown below?
  2. Or should l load it via SystemJS like I load rzjs?
  3. Or should I deploy the zone.js under the @angular folder, and it should work without any configuration?

<environment names="Development"> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.41/system.js"></script> <script src="~/lib/reflect-metadata/reflect.js"></script> <script src="~/lib/zone.js/dist/zone.js"></script> <script src="~/lib/jquery/dist/jquery.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script> <script> window.onload = () => { System.defaultJSExtensions = true; System.config({ map: { 'rxjs': "../../lib/rxjs/bundles/rx.js", '@@angular/core': '../../lib/@@angular/core/bundles/core.umd.js', '@@angular/common': '../../lib/@@angular/common/bundles/common.umd.js', '@@angular/compiler': '../../lib/@@angular/compiler/bundles/compiler.umd.js', '@@angular/platform-browser': '../../lib/@@angular/platform-browser/bundles/platform-browser.umd.js', '@@angular/platform-browser-dynamic': '../../lib/@@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', '@@angular/http': '../../lib/@@angular/http/bundles/http.umd.js', '@@angular/router': '../../lib/@@angular/router/bundles/router.umd.js', '@@angular/forms': '../../lib/@@angular/forms/bundles/forms.umd.js', } }); System.import("../myapp/app.js"); } </script> </environment>


Solution

  • The answer is (1) "Load zone.js globally in the app through script tag". Zone.js performs the critical task of intercepting all of the asynchronous APIs in the browser to create unique execution contexts required by Angular change detection. It is meant to be included before an module loader starts bootstrapping the angular app.