@@ -249,15 +249,18 @@ export function elementPropertyInternal<T>(
249249 nativeOnly : boolean ,
250250) : void {
251251 ngDevMode && assertNotSame ( value , NO_CHANGE as any , 'Incoming value should never be NO_CHANGE.' ) ;
252- let inputData = tNode . inputs ;
253- let dataValue : NodeInputBindings [ typeof propName ] | undefined ;
254- if ( ! nativeOnly && inputData != null && ( dataValue = inputData [ propName ] ) ) {
255- setInputsForProperty ( tView , lView , dataValue , propName , value ) ;
256- if ( isComponentHost ( tNode ) ) markDirtyIfOnPush ( lView , tNode . index ) ;
257- if ( ngDevMode ) {
258- setNgReflectProperties ( lView , tView , tNode , dataValue , value ) ;
252+
253+ if ( ! nativeOnly ) {
254+ const hasSetInput = setInputsForProperty ( tNode , tView , lView , propName , value ) ;
255+
256+ if ( hasSetInput ) {
257+ isComponentHost ( tNode ) && markDirtyIfOnPush ( lView , tNode . index ) ;
258+ ngDevMode && setNgReflectProperties ( lView , tView , tNode , propName , value ) ;
259+ return ; // Stop propcessing if we've matched at least one input.
259260 }
260- } else if ( tNode . type & TNodeType . AnyRNode ) {
261+ }
262+
263+ if ( tNode . type & TNodeType . AnyRNode ) {
261264 const element = getNativeByTNode ( tNode , lView ) as RElement | RComment ;
262265 propName = mapPropName ( propName ) ;
263266
@@ -310,15 +313,33 @@ function setNgReflectProperty(lView: LView, tNode: TNode, attrName: string, valu
310313 }
311314}
312315
313- export function setNgReflectProperties (
316+ function setNgReflectProperties (
314317 lView : LView ,
315318 tView : TView ,
316319 tNode : TNode ,
317- inputConfig : NodeInputBindings [ string ] ,
320+ publicName : string ,
318321 value : any ,
319322) {
320- if ( tNode . type & ( TNodeType . AnyRNode | TNodeType . Container ) ) {
321- // Note: we set the private name of the input as the reflected property, not the public one.
323+ if ( ! ( tNode . type & ( TNodeType . AnyRNode | TNodeType . Container ) ) ) {
324+ return ;
325+ }
326+
327+ // TODO: this is identical to the block below, but will diverge in a future refactor.
328+ // Figure out if we still can't consolidate them somehow.
329+ const inputConfig = tNode . inputs ?. [ publicName ] ;
330+ const hostInputConfig = tNode . hostDirectiveInputs ?. [ publicName ] ;
331+
332+ if ( hostInputConfig ) {
333+ for ( let i = 0 ; i < hostInputConfig . length ; i += 2 ) {
334+ const index = hostInputConfig [ i ] as number ;
335+ const publicName = hostInputConfig [ i + 1 ] as string ;
336+ const def = tView . data [ index ] as DirectiveDef < unknown > ;
337+ setNgReflectProperty ( lView , tNode , def . inputs [ publicName ] [ 0 ] , value ) ;
338+ }
339+ }
340+
341+ // Note: we set the private name of the input as the reflected property, not the public one.
342+ if ( inputConfig ) {
322343 for ( let i = 0 ; i < inputConfig . length ; i += 2 ) {
323344 const index = inputConfig [ i ] as number ;
324345 const lookupName = inputConfig [ i + 1 ] as string ;
@@ -555,7 +576,7 @@ export function storePropertyBindingMetadata(
555576 // Since we don't have a concept of the "first update pass" we need to check for presence of the
556577 // binding meta-data to decide if one should be stored (or if was stored already).
557578 if ( tData [ bindingIndex ] === null ) {
558- if ( tNode . inputs == null || ! tNode . inputs [ propertyName ] ) {
579+ if ( ! tNode . inputs ?. [ propertyName ] && ! tNode . hostDirectiveInputs ?. [ propertyName ] ) {
559580 const propBindingIdxs = tNode . propertyBindings || ( tNode . propertyBindings = [ ] ) ;
560581 propBindingIdxs . push ( bindingIndex ) ;
561582 let bindingMetadata = propertyName ;
@@ -599,25 +620,46 @@ export function handleError(lView: LView, error: any): void {
599620/**
600621 * Set the inputs of directives at the current node to corresponding value.
601622 *
623+ * @param tNode TNode on which the input is being set.
602624 * @param tView The current TView
603625 * @param lView the `LView` which contains the directives.
604- * @param inputs mapping between the public "input" name and privately-known,
605- * possibly minified, property names to write to.
606626 * @param value Value to set.
607627 */
608628export function setInputsForProperty (
629+ tNode : TNode ,
609630 tView : TView ,
610631 lView : LView ,
611- inputs : NodeInputBindings [ typeof publicName ] ,
612632 publicName : string ,
613633 value : unknown ,
614- ) : void {
615- for ( let i = 0 ; i < inputs . length ; i += 2 ) {
616- const index = inputs [ i ] as number ;
617- ngDevMode && assertIndexInRange ( lView , index ) ;
618- const privateName = inputs [ i + 1 ] as string ;
619- const instance = lView [ index ] ;
620- const def = tView . data [ index ] as DirectiveDef < any > ;
621- writeToDirectiveInput ( def , instance , privateName , value ) ;
634+ ) : boolean {
635+ const inputs = tNode . inputs ?. [ publicName ] ;
636+ const hostDirectiveInputs = tNode . hostDirectiveInputs ?. [ publicName ] ;
637+ let hasMatch = false ;
638+
639+ // TODO: this is identical to the block below, but will diverge in a future refactor.
640+ // Figure out if we still can't consolidate them somehow.
641+ if ( hostDirectiveInputs ) {
642+ for ( let i = 0 ; i < hostDirectiveInputs . length ; i += 2 ) {
643+ const index = hostDirectiveInputs [ i ] as number ;
644+ ngDevMode && assertIndexInRange ( lView , index ) ;
645+ const publicName = hostDirectiveInputs [ i + 1 ] as string ;
646+ const def = tView . data [ index ] as DirectiveDef < unknown > ;
647+ writeToDirectiveInput ( def , lView [ index ] , publicName , value ) ;
648+ hasMatch = true ;
649+ }
622650 }
651+
652+ if ( inputs ) {
653+ for ( let i = 0 ; i < inputs . length ; i += 2 ) {
654+ const index = inputs [ i ] as number ;
655+ ngDevMode && assertIndexInRange ( lView , index ) ;
656+ const privateName = inputs [ i + 1 ] as string ;
657+ const instance = lView [ index ] ;
658+ const def = tView . data [ index ] as DirectiveDef < any > ;
659+ writeToDirectiveInput ( def , instance , privateName , value ) ;
660+ hasMatch = true ;
661+ }
662+ }
663+
664+ return hasMatch ;
623665}
0 commit comments