Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!