9
9
import { ChangeDetectorRef , ComponentFactory , ComponentRef , EventEmitter , Injector , OnChanges , ReflectiveInjector , SimpleChange , SimpleChanges , Type } from '@angular/core' ;
10
10
11
11
import * as angular from './angular1' ;
12
- import { ComponentInfo , PropertyBinding } from './component_info' ;
12
+ import { PropertyBinding } from './component_info' ;
13
13
import { $SCOPE } from './constants' ;
14
- import { NgContentSelectorHelper } from './ng_content_selector_helper' ;
15
14
import { getAttributesAsArray , getComponentName , hookupNgModel } from './util' ;
16
15
17
16
const INITIAL_VALUE = {
@@ -27,7 +26,7 @@ export class DowngradeComponentAdapter {
27
26
private changeDetector : ChangeDetectorRef = null ;
28
27
29
28
constructor (
30
- private id : string , private info : ComponentInfo , private element : angular . IAugmentedJQuery ,
29
+ private id : string , private element : angular . IAugmentedJQuery ,
31
30
private attrs : angular . IAttributes , private scope : angular . IScope ,
32
31
private ngModel : angular . INgModelController , private parentInjector : Injector ,
33
32
private $injector : angular . IInjectorService , private $compile : angular . ICompileService ,
@@ -67,9 +66,9 @@ export class DowngradeComponentAdapter {
67
66
68
67
setupInputs ( ) : void {
69
68
const attrs = this . attrs ;
70
- const inputs = this . info . inputs || [ ] ;
69
+ const inputs = this . componentFactory . inputs || [ ] ;
71
70
for ( let i = 0 ; i < inputs . length ; i ++ ) {
72
- const input = new PropertyBinding ( inputs [ i ] ) ;
71
+ const input = new PropertyBinding ( inputs [ i ] . propName , inputs [ i ] . templateName ) ;
73
72
let expr : any /** TODO #9100 */ = null ;
74
73
75
74
if ( attrs . hasOwnProperty ( input . attr ) ) {
@@ -103,7 +102,7 @@ export class DowngradeComponentAdapter {
103
102
}
104
103
}
105
104
106
- const prototype = this . info . component . prototype ;
105
+ const prototype = this . componentFactory . componentType . prototype ;
107
106
if ( prototype && ( < OnChanges > prototype ) . ngOnChanges ) {
108
107
// Detect: OnChanges interface
109
108
this . inputChanges = { } ;
@@ -118,9 +117,9 @@ export class DowngradeComponentAdapter {
118
117
119
118
setupOutputs ( ) {
120
119
const attrs = this . attrs ;
121
- const outputs = this . info . outputs || [ ] ;
120
+ const outputs = this . componentFactory . outputs || [ ] ;
122
121
for ( let j = 0 ; j < outputs . length ; j ++ ) {
123
- const output = new PropertyBinding ( outputs [ j ] ) ;
122
+ const output = new PropertyBinding ( outputs [ j ] . propName , outputs [ j ] . templateName ) ;
124
123
let expr : any /** TODO #9100 */ = null ;
125
124
let assignExpr = false ;
126
125
@@ -158,7 +157,7 @@ export class DowngradeComponentAdapter {
158
157
} ) ;
159
158
} else {
160
159
throw new Error (
161
- `Missing emitter '${ output . prop } ' on component '${ getComponentName ( this . info . component ) } '!` ) ;
160
+ `Missing emitter '${ output . prop } ' on component '${ getComponentName ( this . componentFactory . componentType ) } '!` ) ;
162
161
}
163
162
}
164
163
}
@@ -183,49 +182,31 @@ export class DowngradeComponentAdapter {
183
182
}
184
183
185
184
groupProjectableNodes ( ) {
186
- const ngContentSelectorHelper =
187
- this . parentInjector . get ( NgContentSelectorHelper ) as NgContentSelectorHelper ;
188
- const ngContentSelectors = ngContentSelectorHelper . getNgContentSelectors ( this . info ) ;
189
-
190
- if ( ! ngContentSelectors ) {
191
- throw new Error ( 'Expecting ngContentSelectors for: ' + getComponentName ( this . info . component ) ) ;
192
- }
193
-
194
- return this . _groupNodesBySelector ( ngContentSelectors , this . element . contents ( ) ) ;
185
+ let ngContentSelectors = this . componentFactory . ngContentSelectors ;
186
+ return groupNodesBySelector ( ngContentSelectors , this . element . contents ( ) ) ;
195
187
}
188
+ }
196
189
197
- /**
198
- * Group a set of DOM nodes into `ngContent` groups, based on the given content selectors.
199
- */
200
- private _groupNodesBySelector ( ngContentSelectors : string [ ] , nodes : Node [ ] ) : Node [ ] [ ] {
201
- const projectableNodes : Node [ ] [ ] = [ ] ;
202
- let wildcardNgContentIndex : number ;
190
+ /**
191
+ * Group a set of DOM nodes into `ngContent` groups, based on the given content selectors.
192
+ */
193
+ export function groupNodesBySelector ( ngContentSelectors : string [ ] , nodes : Node [ ] ) : Node [ ] [ ] {
194
+ const projectableNodes : Node [ ] [ ] = [ ] ;
195
+ let wildcardNgContentIndex : number ;
203
196
204
- for ( let i = 0 , ii = ngContentSelectors . length ; i < ii ; ++ i ) {
205
- projectableNodes [ i ] = [ ] ;
206
- }
197
+ for ( let i = 0 , ii = ngContentSelectors . length ; i < ii ; ++ i ) {
198
+ projectableNodes [ i ] = [ ] ;
199
+ }
207
200
208
- for ( let j = 0 , jj = nodes . length ; j < jj ; ++ j ) {
209
- const node = nodes [ j ] ;
210
- const ngContentIndex = findMatchingNgContentIndex ( node , ngContentSelectors ) ;
211
- if ( ngContentIndex != null ) {
212
- projectableNodes [ ngContentIndex ] . push ( node ) ;
213
- }
201
+ for ( let j = 0 , jj = nodes . length ; j < jj ; ++ j ) {
202
+ const node = nodes [ j ] ;
203
+ const ngContentIndex = findMatchingNgContentIndex ( node , ngContentSelectors ) ;
204
+ if ( ngContentIndex != null ) {
205
+ projectableNodes [ ngContentIndex ] . push ( node ) ;
214
206
}
215
-
216
- return projectableNodes ;
217
207
}
218
- }
219
-
220
- let _matches : ( this : any , selector : string ) => boolean ;
221
208
222
- function matchesSelector ( el : any , selector : string ) : boolean {
223
- if ( ! _matches ) {
224
- const elProto = < any > Element . prototype ;
225
- _matches = elProto . matchesSelector || elProto . mozMatchesSelector || elProto . msMatchesSelector ||
226
- elProto . oMatchesSelector || elProto . webkitMatchesSelector ;
227
- }
228
- return _matches . call ( el , selector ) ;
209
+ return projectableNodes ;
229
210
}
230
211
231
212
function findMatchingNgContentIndex ( element : any , ngContentSelectors : string [ ] ) : number {
@@ -247,4 +228,15 @@ function findMatchingNgContentIndex(element: any, ngContentSelectors: string[]):
247
228
ngContentIndices . push ( wildcardNgContentIndex ) ;
248
229
}
249
230
return ngContentIndices . length ? ngContentIndices [ 0 ] : null ;
250
- }
231
+ }
232
+
233
+ let _matches : ( this : any , selector : string ) => boolean ;
234
+
235
+ function matchesSelector ( el : any , selector : string ) : boolean {
236
+ if ( ! _matches ) {
237
+ const elProto = < any > Element . prototype ;
238
+ _matches = elProto . matches || elProto . matchesSelector || elProto . mozMatchesSelector ||
239
+ elProto . msMatchesSelector || elProto . oMatchesSelector || elProto . webkitMatchesSelector ;
240
+ }
241
+ return el . nodeType === Node . ELEMENT_NODE ? _matches . call ( el , selector ) : false ;
242
+ }
0 commit comments