Skip to content

Commit 4351c53

Browse files
feat(bindings): Apply explicit bindings even when no @Input() found.
Closes #45
1 parent a21c479 commit 4351c53

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/directives/uiView.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import {ReflectorReader, reflector} from '../private_import_core';
77

88
import {
9-
UIRouter, isFunction, Transition, parse, HookResult, TransitionHookFn, State, prop, StateDeclaration
9+
UIRouter, isFunction, Transition, parse, HookResult, TransitionHookFn, State, prop, StateDeclaration, inArray
1010
} from "ui-router-core";
1111
import {trace} from "ui-router-core";
1212
import {ViewContext, ViewConfig, ActiveUIView} from "ui-router-core";
@@ -283,15 +283,22 @@ export class UIView {
283283
*/
284284
applyInputBindings(ref: ComponentRef<any>, context: ResolveContext, componentClass) {
285285
let bindings = this.uiViewData.config.viewDecl['bindings'] || {};
286+
let explicitBoundProps = Object.keys(bindings);
286287

287-
var addResolvable = (tuple: InputMapping) => ({
288+
// Supply resolve data to matching @Input('prop') or inputs: ['prop']
289+
let explicitInputTuples = explicitBoundProps
290+
.reduce((acc, key) => acc.concat([{ prop: key, token: bindings[key] }]), []);
291+
let implicitInputTuples = ng2ComponentInputs(componentClass)
292+
.filter(tuple => !inArray(explicitBoundProps, tuple.prop));
293+
294+
295+
const addResolvable = (tuple: InputMapping) => ({
288296
prop: tuple.prop,
289-
resolvable: context.getResolvable(bindings[tuple.prop] || tuple.token)
297+
resolvable: context.getResolvable(tuple.token),
290298
});
291299

292-
// Supply resolve data to matching @Input('prop') or inputs: ['prop']
293-
let inputTuples = ng2ComponentInputs(componentClass);
294-
inputTuples.map(addResolvable)
300+
explicitInputTuples.concat(implicitInputTuples)
301+
.map(addResolvable)
295302
.filter(tuple => tuple.resolvable && tuple.resolvable.resolved)
296303
.forEach(tuple => { ref.instance[tuple.prop] = tuple.resolvable.data });
297304

0 commit comments

Comments
 (0)