( tNode: TNode, tView: TView, lView: LView, target: DirectiveDef<unknown>, publicName: string, value: unknown, )
| 772 | * @param value Value to set. |
| 773 | */ |
| 774 | export function setDirectiveInput( |
| 775 | tNode: TNode, |
| 776 | tView: TView, |
| 777 | lView: LView, |
| 778 | target: DirectiveDef<unknown>, |
| 779 | publicName: string, |
| 780 | value: unknown, |
| 781 | ): boolean { |
| 782 | let hostIndex: number | null = null; |
| 783 | let hostDirectivesStart: number | null = null; |
| 784 | let hostDirectivesEnd: number | null = null; |
| 785 | let hasSet = false; |
| 786 | |
| 787 | if (ngDevMode && !tNode.directiveToIndex?.has(target.type)) { |
| 788 | throw new Error(`Node does not have a directive with type ${target.type.name}`); |
| 789 | } |
| 790 | |
| 791 | const data = tNode.directiveToIndex!.get(target.type)!; |
| 792 | |
| 793 | if (typeof data === 'number') { |
| 794 | hostIndex = data; |
| 795 | } else { |
| 796 | [hostIndex, hostDirectivesStart, hostDirectivesEnd] = data; |
| 797 | } |
| 798 | |
| 799 | if ( |
| 800 | hostDirectivesStart !== null && |
| 801 | hostDirectivesEnd !== null && |
| 802 | tNode.hostDirectiveInputs?.hasOwnProperty(publicName) |
| 803 | ) { |
| 804 | const hostDirectiveInputs = tNode.hostDirectiveInputs[publicName]; |
| 805 | |
| 806 | for (let i = 0; i < hostDirectiveInputs.length; i += 2) { |
| 807 | const index = hostDirectiveInputs[i] as number; |
| 808 | |
| 809 | if (index >= hostDirectivesStart && index <= hostDirectivesEnd) { |
| 810 | ngDevMode && assertIndexInRange(lView, index); |
| 811 | const def = tView.data[index] as DirectiveDef<unknown>; |
| 812 | const hostDirectivePublicName = hostDirectiveInputs[i + 1] as string; |
| 813 | writeToDirectiveInput(def, lView[index], hostDirectivePublicName, value); |
| 814 | hasSet = true; |
| 815 | } else if (index > hostDirectivesEnd) { |
| 816 | // Directives here are in ascending order so we can stop looking once we're past the range. |
| 817 | break; |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | if (hostIndex !== null && target.inputs.hasOwnProperty(publicName)) { |
| 823 | ngDevMode && assertIndexInRange(lView, hostIndex); |
| 824 | writeToDirectiveInput(target, lView[hostIndex], publicName, value); |
| 825 | hasSet = true; |
| 826 | } |
| 827 | |
| 828 | return hasSet; |
| 829 | } |
no test coverage detected
searching dependent graphs…