1
- /** @ng 2api @module directives */ /** */
1
+ /** @ng 2api @module directives */
2
+ /** */
2
3
import {
3
- Component , ComponentFactoryResolver , ViewContainerRef , Input , ComponentRef , Type ,
4
- ReflectiveInjector , ViewChild , Injector , Inject
4
+ Component , ComponentFactoryResolver , ViewContainerRef , Input , ComponentRef , Type , ReflectiveInjector , ViewChild ,
5
+ Injector , Inject
5
6
} from '@angular/core' ;
6
- import { ReflectorReader , reflector } from '../private_import_core' ;
7
-
7
+ import { reflector } from '../private_import_core' ;
8
8
import {
9
- UIRouter , isFunction , Transition , parse , HookResult , TransitionHookFn , State , prop , StateDeclaration , inArray
10
- } from "ui-router-core" ;
11
- import { trace } from "ui-router-core" ;
12
- import { ViewContext , ViewConfig , ActiveUIView } from "ui-router-core" ;
13
- import { Ng2ViewConfig } from "../statebuilders/views" ;
14
- import { ResolveContext , NATIVE_INJECTOR_TOKEN } from "ui-router-core" ;
15
- import { flattenR } from "ui-router-core" ;
16
- import { MergeInjector } from "../mergeInjector" ;
17
- import { Subscription } from 'rxjs/Subscription' ;
9
+ UIRouter , isFunction , Transition , parse , TransitionHookFn , StateDeclaration , inArray , trace , ViewContext , ViewConfig ,
10
+ ActiveUIView , ResolveContext , NATIVE_INJECTOR_TOKEN , flattenR
11
+ } from 'ui-router-core' ;
12
+ import { Ng2ViewConfig } from '../statebuilders/views' ;
13
+ import { MergeInjector } from '../mergeInjector' ;
18
14
19
15
/** @hidden */
20
16
let id = 0 ;
@@ -39,7 +35,7 @@ interface InputMapping {
39
35
*
40
36
* @internalapi
41
37
*/
42
- const ng2ComponentInputs = ( ng2CompClass : Type < any > ) => {
38
+ const ng2ComponentInputs = ( ng2CompClass : Type < any > , component : any ) => {
43
39
/** Get "@Input('foo') _foo" inputs */
44
40
let props = reflector . propMetadata ( ng2CompClass ) ;
45
41
let _props = Object . keys ( props || { } )
@@ -61,7 +57,12 @@ const ng2ComponentInputs = (ng2CompClass: Type<any>) => {
61
57
. reduce ( flattenR , [ ] )
62
58
. map ( input => ( { token : input , prop : input } ) ) ;
63
59
64
- return _props . concat ( inputs ) as InputMapping [ ] ;
60
+ /** Get @ResolveData('foo') _foo" inputs */
61
+ let __inputs = component . __inputs || { } ;
62
+ let resolves = Object . keys ( __inputs )
63
+ . map ( key => ( { token : key , prop : __inputs [ key ] } ) ) ;
64
+
65
+ return _props . concat ( inputs ) . concat ( resolves ) as InputMapping [ ] ;
65
66
} ;
66
67
67
68
/**
@@ -282,15 +283,16 @@ export class UIView {
282
283
* to the resolve data.
283
284
*/
284
285
applyInputBindings ( ref : ComponentRef < any > , context : ResolveContext , componentClass ) {
285
- let bindings = this . uiViewData . config . viewDecl [ 'bindings' ] || { } ;
286
- let explicitBoundProps = Object . keys ( bindings ) ;
286
+ const component = ref . instance ;
287
+ const bindings = this . uiViewData . config . viewDecl [ 'bindings' ] || { } ;
288
+ const explicitBoundProps = Object . keys ( bindings ) ;
287
289
288
290
// Supply resolve data to matching @Input ('prop') or inputs: ['prop']
289
- let explicitInputTuples = explicitBoundProps
291
+ const explicitInputTuples = explicitBoundProps
290
292
. reduce ( ( acc , key ) => acc . concat ( [ { prop : key , token : bindings [ key ] } ] ) , [ ] ) ;
291
- let implicitInputTuples = ng2ComponentInputs ( componentClass )
292
- . filter ( tuple => ! inArray ( explicitBoundProps , tuple . prop ) ) ;
293
293
294
+ const implicitInputTuples = ng2ComponentInputs ( componentClass , component )
295
+ . filter ( tuple => ! inArray ( explicitBoundProps , tuple . prop ) ) ;
294
296
295
297
const addResolvable = ( tuple : InputMapping ) => ( {
296
298
prop : tuple . prop ,
@@ -300,7 +302,7 @@ export class UIView {
300
302
explicitInputTuples . concat ( implicitInputTuples )
301
303
. map ( addResolvable )
302
304
. filter ( tuple => tuple . resolvable && tuple . resolvable . resolved )
303
- . forEach ( tuple => { ref . instance [ tuple . prop ] = tuple . resolvable . data } ) ;
305
+ . forEach ( tuple => { component [ tuple . prop ] = tuple . resolvable . data } ) ;
304
306
305
307
// Initiate change detection for the newly created component
306
308
ref . changeDetectorRef . detectChanges ( ) ;
0 commit comments