Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: third_party/pkg/angular/lib/bootstrap.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 or
7 *
8 * - [NgCoreModule]
9 * - [NgCoreDomModule]
10 * - [NgFilterModule]
11 * - [NgPerfModule]
12 */
13 class AngularModule extends Module {
14 AngularModule() {
15 install(new NgCoreModule());
16 install(new NgCoreDomModule());
17 install(new NgDirectiveModule());
18 install(new NgFilterModule());
19 install(new NgPerfModule());
20 install(new NgRoutingModule());
21
22 type(MetadataExtractor);
23 value(Expando, _elementExpando);
24 }
25 }
26
27 Injector _defaultInjectorFactory(List<Module> modules) =>
28 new DynamicInjector(modules: modules);
29
30 /**
31 * This method is the main entry point to an angular application.
32 *
33 * # The [ngBootstrap] is responsible for:
34 *
35 * 1. Locating the root element of the application,
36 * 2. Creating Angular [NgZone]
37 * 3. Inside the [NgZone] create an injector
38 * 4. Retrieve the [Compiler] and compile the root eleement
39 *
40 *
41 * # Parameters:
42 *
43 * - [module] Option application module to add to the [Injector].
44 * - [modules] Optional list of [Module]s to add to the [Injector] (if more th en one is needed).
45 * - [element] Optional root element of the application. If non specified, the
46 * the root element is looked up usinge the [selector]. If selector can not
47 * identify a root, the root [HTTML] element is used for bootstraping.
48 * - [selector] Optional CSS selector used to locate the root element for the application.
49 * - [injectorFactor] Optinoal factory responsible for creating the injector.
50 *
51 *
52 *
53 * # A typical way to boostrap an Angular application:
54 *
55 * Module myAppModule = new Module();
56 * myAppModule.type(MyType);
57 * ....
58 * Injector injector = ngBootstrap(module: myAppModule);
59 */
60 Injector ngBootstrap({
61 Module module: null,
62 List<Module> modules: null,
63 dom.Element element: null,
64 String selector: '[ng-app]',
65 Injector injectorFactory(List<Module> modules): _defaultInjectorFactory} ) {
66 _publishToJavaScript();
67
68 var ngModules = [new AngularModule()];
69 if (module != null) ngModules.add(module);
70 if (modules != null) ngModules.addAll(modules);
71 if (element == null) {
72 element = dom.querySelector(selector);
73 var document = dom.window.document;
74 if (element == null) element = document.childNodes.firstWhere((e) => e is do m.Element);
75 }
76
77 // The injector must be created inside the zone, so we create the
78 // zone manually and give it back to the injector as a value.
79 NgZone zone = new NgZone();
80 ngModules.add(new Module()..value(NgZone, zone));
81
82 return zone.run(() {
83 var rootElements = [element];
84 Injector injector = injectorFactory(ngModules);
85 injector.get(Compiler)(rootElements)(injector, rootElements);
86 return injector;
87 });
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698