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

Class Container

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

Source from the content-addressed store, hash-verified

388 `;
389
390 @Component({
391 selector: 'app-container',
392 encapsulation: ViewEncapsulation.None,
393 template: `
394 <button (click)="toggle()">{{ state() ? 'Leave' : 'Enter' }}</button>
395
396 <ng-template #template>
397 <ng-content></ng-content>
398 </ng-template>
399 `,
400 })
401 class Container {
402 private readonly viewContainerRef = inject(ViewContainerRef);
403
404 protected readonly template = viewChild.required<TemplateRef<any>>('template');
405
406 protected state = signal<boolean>(false);
407
408 protected toggle() {
409 this.state() ? this.destroy() : this.create();
410 }
411
412 protected create() {
413 this.state.set(true);
414 this.viewContainerRef.createEmbeddedView(this.template());
415 }
416
417 protected destroy() {
418 this.state.set(false);
419 this.viewContainerRef.clear();
420 }
421 }
422
423 @Component({
424 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