Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

166
Vistas
Not able to use cx-media component with a media container

Below codes on Spartacus version 2.0 work fine. the template file:

<ng-container *ngIf="data$ | async as data">
  <cx-media [container]="data.media" [title]="data | json"></cx-media>
</ng-container>

the ts file:

@Component({
  selector: 'app-custom-banner',
  templateUrl: './custom-banner.component.html',
})
export class CustomBannerComponent {

  data$: Observable<CmsBannerComponent> = this.componentData.data$;

  constructor(protected componentData: CmsComponentData<CmsBannerComponent>) {}

}

But it's not compiling on spartacus version 4 and giving below errors.

Type 'CmsBannerComponentMedia | CmsResponsiveBannerComponentMedia | undefined' is not assignable to type 'MediaContainer'.
  Type 'undefined' is not assignable to type 'MediaContainer'.ngtsc(2322)

Error: src/app/spartacus/features/custom-cms-components/custom-banner/custom-banner.component.html:3:14 - error TS2322: Type 'CmsBannerComponentMedia | CmsResponsiveBannerComponentMedia | undefined' is not assignable to type 'MediaContainer'.
  Type 'undefined' is not assignable to type 'MediaContainer'.

3   <cx-media [container]="data.media" [title]="data | json"></cx-media>
               ~~~~~~~~~

  src/app/spartacus/features/custom-cms-components/custom-banner/custom-banner.component.ts:8:16
    8   templateUrl: './custom-banner.component.html',
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component CustomBannerComponent.
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I reproduced the issue and created a bug ticket. You can observe it, and update your project when it will be done and released.

For now, I can suggest only ugly workarounds like:

  • locally use $any(...): [container]="$any(data.media)"
  • or globally change the flag:
  "angularCompilerOptions": {
    "strictTemplates": false
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda