| OLD | NEW |
| (Empty) | |
| 1 part of angular; |
| 2 |
| 3 /** |
| 4 * This is the top level module which describes the whole of angular. |
| 5 * |
| 6 * The Module is made up of |
| 7 * |
| 8 * - [NgCoreModule] |
| 9 * - [NgCoreDomModule] |
| 10 * - [NgDirectiveModule] |
| 11 * - [NgFilterModule] |
| 12 * - [NgPerfModule] |
| 13 * - [NgRoutingModule] |
| 14 */ |
| 15 class AngularModule extends Module { |
| 16 AngularModule() { |
| 17 install(new NgCoreModule()); |
| 18 install(new NgCoreDomModule()); |
| 19 install(new NgDirectiveModule()); |
| 20 install(new NgFilterModule()); |
| 21 install(new NgPerfModule()); |
| 22 install(new NgRoutingModule()); |
| 23 |
| 24 type(MetadataExtractor); |
| 25 value(Expando, _elementExpando); |
| 26 value(NgApp, new NgApp(dom.window.document.documentElement)); |
| 27 } |
| 28 } |
| 29 |
| 30 Injector _defaultInjectorFactory(List<Module> modules) => |
| 31 new DynamicInjector(modules: modules); |
| 32 |
| 33 /** |
| 34 * This method is the main entry point to an angular application. |
| 35 * |
| 36 * # The [ngBootstrap] is responsible for: |
| 37 * |
| 38 * 1. Locating the root element of the application, |
| 39 * 2. Creating Angular [NgZone] |
| 40 * 3. Inside the [NgZone] create an injector |
| 41 * 4. Retrieve the [Compiler] and compile the root eleement |
| 42 * |
| 43 * |
| 44 * # Parameters: |
| 45 * |
| 46 * - [module] Option application module to add to the [Injector]. |
| 47 * - [modules] Optional list of [Module]s to add to the [Injector] (if more th
an one is needed). |
| 48 * - [element] Optional root element of the application. If non specified, the |
| 49 * the root element is looked up using the [selector]. If selector can not |
| 50 * identify a root, the root [HTML] element is used for bootstraping. |
| 51 * - [selector] Optional CSS selector used to locate the root element for the
application. |
| 52 * - [injectorFactor] Optional factory responsible for creating the injector. |
| 53 * |
| 54 * |
| 55 * |
| 56 * # A typical way to boostrap an Angular application: |
| 57 * |
| 58 * Module myAppModule = new Module(); |
| 59 * myAppModule.type(MyType); |
| 60 * .... |
| 61 * Injector injector = ngBootstrap(module: myAppModule); |
| 62 */ |
| 63 Injector ngBootstrap({ |
| 64 Module module: null, |
| 65 List<Module> modules: null, |
| 66 dom.Element element: null, |
| 67 String selector: '[ng-app]', |
| 68 Injector injectorFactory(List<Module> modules): _defaultInjectorFactory}) { |
| 69 _publishToJavaScript(); |
| 70 |
| 71 var ngModules = [new AngularModule()]; |
| 72 if (module != null) ngModules.add(module); |
| 73 if (modules != null) ngModules.addAll(modules); |
| 74 if (element == null) { |
| 75 element = dom.querySelector(selector); |
| 76 var document = dom.window.document; |
| 77 if (element == null) { |
| 78 element = document.childNodes.firstWhere((e) => e is dom.Element); |
| 79 } |
| 80 } |
| 81 |
| 82 // The injector must be created inside the zone, so we create the |
| 83 // zone manually and give it back to the injector as a value. |
| 84 NgZone zone = new NgZone(); |
| 85 ngModules.add(new Module() |
| 86 ..value(NgZone, zone) |
| 87 ..value(NgApp, new NgApp(element))); |
| 88 |
| 89 return zone.run(() { |
| 90 var rootElements = [element]; |
| 91 Injector injector = injectorFactory(ngModules); |
| 92 injector.get(Compiler)(rootElements, injector.get(DirectiveMap)) |
| 93 (injector, rootElements); |
| 94 return injector; |
| 95 }); |
| 96 } |
| 97 |
| 98 /// Holds a reference to the root of the application used by ngBootstrap. |
| 99 class NgApp { |
| 100 final dom.Element root; |
| 101 NgApp(this.root); |
| 102 } |
| OLD | NEW |