1+ <!doctype html>
2+ < html >
3+ < head >
4+ < meta charset ="utf-8 " />
5+
6+ < title >
7+ Provider And Directive Arrays Can Be Mixed-Depth In Angular 2 Beta 6
8+ </ title >
9+ </ head >
10+ < body >
11+
12+ < h1 >
13+ Provider And Directive Arrays Can Be Mixed-Depth In Angular 2 Beta 6
14+ </ h1 >
15+
16+ < my-app >
17+ Loading...
18+ </ my-app >
19+
20+ <!-- Load demo scripts. -->
21+ < script type ="text/javascript " src ="../../vendor/angularjs-2-beta/6/es6-shim.min.js "> </ script >
22+ < script type ="text/javascript " src ="../../vendor/angularjs-2-beta/6/Rx.umd.min.js "> </ script >
23+ < script type ="text/javascript " src ="../../vendor/angularjs-2-beta/6/angular2-polyfills.min.js "> </ script >
24+ < script type ="text/javascript " src ="../../vendor/angularjs-2-beta/6/angular2-all.umd.js "> </ script >
25+ <!-- AlmondJS - minimal implementation of RequireJS. -->
26+ < script type ="text/javascript " src ="../../vendor/angularjs-2-beta/6/almond.js "> </ script >
27+ < script type ="text/javascript ">
28+
29+ // Defer bootstrapping until all of the components have been declared.
30+ // --
31+ // NOTE: Not all components have to be required here since they will be
32+ // implicitly required by other components.
33+ requirejs (
34+ [ "AppComponent" ] ,
35+ function run ( AppComponent ) {
36+
37+ ng . platform . browser . bootstrap (
38+ AppComponent ,
39+
40+ // As we define the provider array, notice that we are wrapping each
41+ // multi-value instance in an increasingly deep nested array. This
42+ // way, we can test how much the array will be flattened during the
43+ // bootstrapping process.
44+ [
45+ ng . core . provide (
46+ "VALUE_COLLECTION" ,
47+ {
48+ useValue : "level-0" ,
49+ multi : true
50+ }
51+ ) ,
52+ [
53+ ng . core . provide (
54+ "VALUE_COLLECTION" ,
55+ {
56+ useValue : "level-1" ,
57+ multi : true
58+ }
59+ )
60+ ] ,
61+ [
62+ [
63+ ng . core . provide (
64+ "VALUE_COLLECTION" ,
65+ {
66+ useValue : "level-2" ,
67+ multi : true
68+ }
69+ )
70+ ]
71+ ] ,
72+ [
73+ [
74+ [
75+ ng . core . provide (
76+ "VALUE_COLLECTION" ,
77+ {
78+ useValue : "level-3" ,
79+ multi : true
80+ }
81+ )
82+ ]
83+ ]
84+ ] ,
85+ [
86+ [
87+ [
88+ [
89+ ng . core . provide (
90+ "VALUE_COLLECTION" ,
91+ {
92+ useValue : "level-4" ,
93+ multi : true
94+ }
95+ )
96+ ]
97+ ]
98+ ]
99+ ] ,
100+ [
101+ [
102+ [
103+ [
104+ [
105+ ng . core . provide (
106+ "VALUE_COLLECTION" ,
107+ {
108+ useValue : "level-5" ,
109+ multi : true
110+ }
111+ )
112+ ]
113+ ]
114+ ]
115+ ]
116+ ]
117+ ]
118+ ) ;
119+
120+ }
121+ ) ;
122+
123+
124+ // --------------------------------------------------------------------------- //
125+ // --------------------------------------------------------------------------- //
126+
127+
128+ // I provide the root App component.
129+ define (
130+ "AppComponent" ,
131+ function registerAppComponent ( ) {
132+
133+ // All of these directives will select against the "p" element.
134+ var PTag0 = require ( "PTag0" ) ;
135+ var PTag1 = require ( "PTag1" ) ;
136+ var PTag2 = require ( "PTag2" ) ;
137+ var PTag3 = require ( "PTag3" ) ;
138+ var PTag4 = require ( "PTag4" ) ;
139+ var PTag5 = require ( "PTag5" ) ;
140+
141+ // Configure the App component definition.
142+ ng . core
143+ . Component ( {
144+ selector : "my-app" ,
145+
146+ // As we define the directive array, notice that we are wrapping
147+ // each directive class in an increasingly deep nested array.
148+ // This way, we can test how much the array will be flattened
149+ // during the linking process.
150+ directives : [
151+ PTag0 ,
152+ [ PTag1 ] ,
153+ [ [ PTag2 ] ] ,
154+ [ [ [ PTag3 ] ] ] ,
155+ [ [ [ [ PTag4 ] ] ] ] ,
156+ [ [ [ [ [ PTag5 ] ] ] ] ]
157+ ] ,
158+ template :
159+ `
160+ <p>
161+ Such arrays! Much deep! So mixed!
162+ </p>
163+ `
164+ } )
165+ . Class ( {
166+ constructor : AppController
167+ } )
168+ ;
169+
170+ AppController . parameters = [ new ng . core . Inject ( "VALUE_COLLECTION" ) ] ;
171+
172+ return ( AppController ) ;
173+
174+
175+ // I control the App component.
176+ function AppController ( values ) {
177+
178+ var vm = this ;
179+
180+ // Let's log-out the values that were collected from our mixed-depth
181+ // provider collection.
182+ console . log ( "Provider Values:" ) ;
183+ console . log ( values ) ;
184+
185+ }
186+
187+ }
188+ ) ;
189+
190+
191+ // --------------------------------------------------------------------------- //
192+ // --------------------------------------------------------------------------- //
193+
194+
195+ // Let's setup several Directives that all select for "P". This way, we can see
196+ // how many of them get instantiated in the App component with the mixed-depth
197+ // directive array.
198+ [ 0 , 1 , 2 , 3 , 4 , 5 ] . forEach (
199+ function iterator ( depth ) {
200+
201+ define (
202+ ( "PTag" + depth ) ,
203+ function registerPTag ( ) {
204+
205+ // Configure the PTag directive definition.
206+ // --
207+ // CAUTION: Normally, I wouldn't return the value of this
208+ // method chain. However, I was running into a bug that I didn't
209+ // understand in which the wrong directives were being linked
210+ // if I returned the constructor reference. I'll investigate that
211+ // in a subsequent blog post (if I can figure it out).
212+ return ng . core
213+ . Directive ( {
214+ selector : "p"
215+ } )
216+ . Class ( {
217+ constructor : function ( ) {
218+
219+ console . log ( "PTag" + depth + " constructed." ) ;
220+
221+ }
222+ } )
223+ ;
224+
225+ }
226+ ) ;
227+
228+ }
229+ ) ;
230+
231+ </ script >
232+
233+ </ body >
234+ </ html >
0 commit comments