Skip to content

Commit 4f53f81

Browse files
fix(ng2.UiView): fix input resolve binding
1 parent e088210 commit 4f53f81

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/ng2/directives/uiView.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const ng2ComponentInputs = (ng2CompClass) => {
3838
// Only Inputs
3939
.filter(tuple => tuple.anno instanceof InputMetadata)
4040
// If they have a bindingPropertyName, i.e. "@Input('foo') _foo", then foo, else _foo
41-
.map(tuple => ({ resolve: tuple.anno.bindingPropertyName || tuple.key, prop: tuple.key }));
41+
.map(tuple => ({ token: tuple.anno.bindingPropertyName || tuple.key, prop: tuple.key }));
4242

4343
/** Get "inputs: ['foo']" inputs */
4444
let inputs = Reflect['getMetadata']('annotations', ng2CompClass)
@@ -48,7 +48,7 @@ const ng2ComponentInputs = (ng2CompClass) => {
4848
.map(x => x.inputs)
4949
// Flatten
5050
.reduce((acc, arr) => acc.concat(arr), [])
51-
.map(input => ({ resolve: input, prop: input }));
51+
.map(input => ({ token: input, prop: input }));
5252

5353
return _props.concat(inputs);
5454
};
@@ -184,7 +184,7 @@ export class UiView {
184184
let context = new ResolveContext(config.path);
185185
let resolvables = context.getTokens().map(token => context.getResolvable(token)).filter(r => r.resolved);
186186
let rawProviders = resolvables.map(r => ({ provide: r.token, useValue: r.data }));
187-
rawProviders.push(provide(UiView.PARENT_INJECT, { useValue: { context: config.viewDecl.$context, fqn: uiViewData.fqn } }));
187+
rawProviders.push({ provide: UiView.PARENT_INJECT, useValue: { context: config.viewDecl.$context, fqn: uiViewData.fqn } });
188188

189189
// Get the component class from the view declaration. TODO: allow promises?
190190
let componentType = <Type> viewDecl.component;
@@ -196,13 +196,17 @@ export class UiView {
196196

197197
// TODO: wire uiCanExit and uiOnParamsChanged callbacks
198198

199-
// Supply resolve data to matching @Input('prop') or inputs: ['prop']
200-
let inputs = ng2ComponentInputs(componentType);
201199
let bindings = viewDecl['bindings'] || {};
200+
var addResolvable = tuple => ({
201+
prop: tuple.prop,
202+
resolvable: context.getResolvable(bindings[tuple.prop] || tuple.token)
203+
});
202204

203-
inputs.map(tuple => ({ prop: tuple.prop, resolve: bindings[tuple.prop] || tuple.resolve }))
204-
.filter(tuple => resolvables[tuple.resolve] !== undefined)
205-
.forEach(tuple => { ref.instance[tuple.prop] = resolvables[tuple.resolve].data });
205+
// Supply resolve data to matching @Input('prop') or inputs: ['prop']
206+
let inputTuples = ng2ComponentInputs(componentType);
207+
inputTuples.map(addResolvable)
208+
.filter(tuple => tuple.resolvable && tuple.resolvable.resolved)
209+
.forEach(tuple => { ref.instance[tuple.prop] = tuple.resolvable.data });
206210

207211
// Initiate change detection for the newly created component
208212
ref.changeDetectorRef.detectChanges();

test/ng1/viewSpec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ describe('view', function() {
6666
let $view = new ViewService();
6767
$view.viewConfigFactory("ng1", ng1ViewConfigFactory);
6868

69-
path = [root, state].map(_state => new PathNode(_state));
70-
path = PathFactory.applyViewConfigs($view, path);
69+
let states = [root, state];
70+
path = states.map(_state => new PathNode(_state));
71+
PathFactory.applyViewConfigs($view, path, states);
7172
});
7273

7374
it('uses the controllerProvider to get controller dynamically', inject(function ($view, $q) {

0 commit comments

Comments
 (0)