11import {
2- Attribute ,
32 ChangeDetectionStrategy ,
43 Component ,
54 CUSTOM_ELEMENTS_SCHEMA ,
65 ElementRef ,
6+ HostAttributeToken ,
7+ inject ,
78 input ,
89 signal ,
910 viewChild ,
@@ -57,8 +58,9 @@ export class Box {
5758 position = input < NgtVector3 > ( 0 ) ;
5859 color = input ( 'turquoise' ) ;
5960
60- constructor ( @ Attribute ( 'context' ) context : string ) {
61+ constructor ( ) {
6162 const store = injectStore ( ) ;
63+ const context = inject ( new HostAttributeToken ( 'context' ) , { optional : true } ) ;
6264 console . log ( { context, store : store . snapshot . id , previous : store . snapshot . previousRoot } ) ;
6365 }
6466
@@ -97,6 +99,8 @@ export class NestedBox {
9799@Component ( {
98100 selector : 'app-scene' ,
99101 template : `
102+ <ngt-color attach="background" *args="['#303030']" />
103+
100104 <ngt-ambient-light [intensity]="Math.PI" />
101105 <ngt-directional-light [position]="5" [intensity]="Math.PI" />
102106
@@ -109,81 +113,81 @@ export class NestedBox {
109113
110114 <ngt-primitive *args="[mesh]" [parameters]="{ position: [2, 0, 0] }" />
111115
112- <!-- < app-nested-box [position]="[-3, 0, 0]" />-- >
113-
114- <!-- <!– three element under condition –> -->
115- <!-- @if (show()) {-->
116- <!-- <ngt-mesh [position]="[3, 0, 0]">-- >
117- <!-- <ngt-icosahedron-geometry />-- >
118- <!-- <ngt-mesh-normal-material />-- >
119- <!-- </ngt-mesh>-- >
120- <!-- }-->
121-
122- <!-- <!– component wrapping three elemnent –> -->
123- <!-- < app-box [position]="[1, 0, 0]" />-- >
124-
125- <!-- <!– with input for default content –> -->
126- <!-- < app-box [position]="[-1, 0, 0]" color="red" />-- >
127-
128- <!-- <!– with custom ng content –> -->
129- <!-- < app-box [position]="[0, 1, 0]">-- >
130- <!-- <ngt-mesh-standard-material color="green" />-- >
131- <!-- < /app-box>-- >
132-
133- <!-- <!– with property binding for input for default content –> -->
134- <!-- < app-box [position]="[0, -1, 0]" [color]="color()" />-- >
135-
136- <!-- <!– component under condition –> -->
137- <!-- @if (show()) {-->
138- <!-- <app-box [position]="[1, 1, 0]">-- >
139- <!-- @if (show()) {-->
140- <!-- <ngt-mesh-phong-material color="yellow" />-- >
141- <!-- }-->
142- <!-- </app-box>-- >
143- <!-- }-->
144-
145- <!-- <!– component with component as content –> -->
146- <!-- < app-box [position]="[-1, -1, 0]" color="brown" context="in root">-- >
147- <!-- <app-box data-children [position]="[-0.5, -0.5, 0]" color="pink" context="in box content in root" />-- >
148- <!-- < /app-box>-- >
149-
150- <!-- <!– component with both content projection slots –> -->
151- <!-- < app-box [position]="[-1, 1, 0]">-- >
152- <!-- <ngt-mesh-lambert-material color="orange" />-- >
153- <!-- <app-box data-children [position]="[-0.5, 0.5, 0]" color="skyblue" />-- >
154- <!-- < /app-box>-- >
155-
156- <!-- <!– component with conditional content slots –> -->
157- <!-- < app-box [position]="[1, -1, 0]">-- >
158- <!-- @if (true) {-->
159- <!-- <ngt-mesh-normal-material />-- >
160- <!-- }-->
161-
162- <!-- @if (show()) {-->
163- <!-- <app-box data-children [position]="[0.5, -0.5, 0]" color="black" />-- >
164- <!-- }-->
165- <!-- < /app-box>-- >
166-
167- <!-- <!– component with conditional template –> -->
168- <!-- < app-condition-box [position]="[0, 2, 0]" />-- >
169-
170- <!-- <!– component with conditional template under condition –> -->
171- <!-- @if (show()) {-->
172- <!-- <app-condition-box [position]="[0, -2, 0]" />-- >
173- <!-- }-->
116+ <app-nested-box [position]="[-3, 0, 0]" />
117+
118+ <!-- three element under condition -->
119+ @if (show()) {
120+ <ngt-mesh [position]="[3, 0, 0]">
121+ <ngt-icosahedron-geometry />
122+ <ngt-mesh-normal-material />
123+ </ngt-mesh>
124+ }
125+
126+ <!-- component wrapping three elemnent -->
127+ <app-box [position]="[1, 0, 0]" />
128+
129+ <!-- with input for default content -->
130+ <app-box [position]="[-1, 0, 0]" color="red" />
131+
132+ <!-- with custom ng content -->
133+ <app-box [position]="[0, 1, 0]">
134+ <ngt-mesh-standard-material color="green" />
135+ </app-box>
136+
137+ <!-- with property binding for input for default content -->
138+ <app-box [position]="[0, -1, 0]" [color]="color()" />
139+
140+ <!-- component under condition -->
141+ @if (show()) {
142+ <app-box [position]="[1, 1, 0]">
143+ @if (show()) {
144+ <ngt-mesh-phong-material color="yellow" />
145+ }
146+ </app-box>
147+ }
148+
149+ <!-- component with component as content -->
150+ <app-box [position]="[-1, -1, 0]" color="brown" context="in root">
151+ <app-box data-children [position]="[-0.5, -0.5, 0]" color="pink" context="in box content in root" />
152+ </app-box>
153+
154+ <!-- component with both content projection slots -->
155+ <app-box [position]="[-1, 1, 0]">
156+ <ngt-mesh-lambert-material color="orange" />
157+ <app-box data-children [position]="[-0.5, 0.5, 0]" color="skyblue" />
158+ </app-box>
159+
160+ <!-- component with conditional content slots -->
161+ <app-box [position]="[1, -1, 0]">
162+ @if (true) {
163+ <ngt-mesh-normal-material />
164+ }
165+
166+ @if (show()) {
167+ <app-box data-children [position]="[0.5, -0.5, 0]" color="black" />
168+ }
169+ </app-box>
170+
171+ <!-- component with conditional template -->
172+ <app-condition-box [position]="[0, 2, 0]" />
173+
174+ <!-- component with conditional template under condition -->
175+ @if (show()) {
176+ <app-condition-box [position]="[0, -2, 0]" />
177+ }
174178 </ngt-group>
175179
176180 <!-- portal -->
177- <!-- < ngt-portal [container]="virtualScene">-- >
178- <!-- <ngt-group *portalContent>-- >
179- <!-- <!– component inside portal –> -->
180- <!-- <app-box context="in portal" />-- >
181-
182- <!-- @if (show()) {-->
183- <!-- <app-box context="in portal in condition" />-- >
184- <!-- }-->
185- <!-- </ngt-group>-- >
186- <!-- < /ngt-portal>-- >
181+ <ngt-portal [container]="virtualScene">
182+ <ngt-group *portalContent>
183+ <!-- component inside portal -->
184+ <app-box context="in portal" />
185+
186+ @if (show()) {
187+ <app-box context="in portal in condition" />
188+ }
189+ </ngt-group>
190+ </ngt-portal>
187191 ` ,
188192 imports : [ NgtArgs , Box , ConditionBox , NgtPortalDeclarations , NestedBox ] ,
189193 changeDetection : ChangeDetectionStrategy . OnPush ,
0 commit comments