MCPcopy Create free account
hub / github.com/angular/angular / Container

Class Container

packages/core/test/acceptance/authoring/signal_inputs_spec.ts:402–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

400 `;
401
402 @Component({
403 selector: 'app-container',
404 encapsulation: ViewEncapsulation.None,
405 template: `
406 <button (click)="toggle()">{{ state() ? 'Leave' : 'Enter' }}</button>
407
408 <ng-template #template>
409 <ng-content></ng-content>
410 </ng-template>
411 `,
412 })
413 class Container {
414 private readonly viewContainerRef = inject(ViewContainerRef);
415
416 protected readonly template = viewChild.required<TemplateRef<any>>('template');
417
418 protected state = signal<boolean>(false);
419
420 protected toggle() {
421 this.state() ? this.destroy() : this.create();
422 }
423
424 protected create() {
425 this.state.set(true);
426 this.viewContainerRef.createEmbeddedView(this.template());
427 }
428
429 protected destroy() {
430 this.state.set(false);
431 this.viewContainerRef.clear();
432 }
433 }
434
435 @Component({
436 selector: 'app-content',

Callers

nothing calls this directly

Calls 4

ComponentInterface · 0.90
injectFunction · 0.90
signalFunction · 0.90
requiredMethod · 0.45

Tested by

no test coverage detected