8
8
9
9
import { AST , BindingPipe , ImplicitReceiver , PropertyRead , PropertyWrite , RecursiveAstVisitor , SafePropertyRead } from '../../expression_parser/ast' ;
10
10
import { SelectorMatcher } from '../../selector' ;
11
- import { BoundAttribute , BoundEvent , BoundText , Content , DeferredBlock , DeferredBlockError , DeferredBlockLoading , DeferredBlockPlaceholder , DeferredTrigger , Element , ForLoopBlock , ForLoopBlockEmpty , HoverDeferredTrigger , Icu , IfBlock , IfBlockBranch , InteractionDeferredTrigger , Node , Reference , SwitchBlock , SwitchBlockCase , Template , Text , TextAttribute , UnknownBlock , Variable , ViewportDeferredTrigger , Visitor } from '../r3_ast' ;
11
+ import { BoundAttribute , BoundEvent , BoundText , Comment , Content , DeferredBlock , DeferredBlockError , DeferredBlockLoading , DeferredBlockPlaceholder , DeferredTrigger , Element , ForLoopBlock , ForLoopBlockEmpty , HoverDeferredTrigger , Icu , IfBlock , IfBlockBranch , InteractionDeferredTrigger , Node , Reference , SwitchBlock , SwitchBlockCase , Template , Text , TextAttribute , UnknownBlock , Variable , ViewportDeferredTrigger , Visitor } from '../r3_ast' ;
12
12
13
13
import { BoundTarget , DirectiveMeta , ReferenceTarget , ScopedNode , Target , TargetBinder } from './t2_api' ;
14
14
import { createCssSelector } from './template' ;
@@ -798,14 +798,29 @@ export class R3BoundTarget<DirectiveT extends DirectiveMeta> implements BoundTar
798
798
const name = trigger . reference ;
799
799
800
800
if ( name === null ) {
801
- const children = block . placeholder ? block . placeholder . children : null ;
802
-
803
- // If the trigger doesn't have a reference, it is inferred as the root element node of the
804
- // placeholder, if it only has one root node. Otherwise it's ambiguous so we don't
805
- // attempt to resolve further.
806
- return children !== null && children . length === 1 && children [ 0 ] instanceof Element ?
807
- children [ 0 ] :
808
- null ;
801
+ let trigger : Element | null = null ;
802
+
803
+ if ( block . placeholder !== null ) {
804
+ for ( const child of block . placeholder . children ) {
805
+ // Skip over comment nodes. Currently by default the template parser doesn't capture
806
+ // comments, but we have a safeguard here just in case since it can be enabled.
807
+ if ( child instanceof Comment ) {
808
+ continue ;
809
+ }
810
+
811
+ // We can only infer the trigger if there's one root element node. Any other
812
+ // nodes at the root make it so that we can't infer the trigger anymore.
813
+ if ( trigger !== null ) {
814
+ return null ;
815
+ }
816
+
817
+ if ( child instanceof Element ) {
818
+ trigger = child ;
819
+ }
820
+ }
821
+ }
822
+
823
+ return trigger ;
809
824
}
810
825
811
826
const outsideRef = this . findEntityInScope ( block , name ) ;
@@ -821,7 +836,7 @@ export class R3BoundTarget<DirectiveT extends DirectiveMeta> implements BoundTar
821
836
}
822
837
823
838
// If the trigger couldn't be found in the main block, check the
824
- // placeholder block which is shown before the main block has loaded.
839
+ // placeholder block which is shown before the main block has loaded.
825
840
if ( block . placeholder !== null ) {
826
841
const refInPlaceholder = this . findEntityInScope ( block . placeholder , name ) ;
827
842
const targetInPlaceholder =
0 commit comments