How to use Document/Window objetcts in SAP Spartacus?

 Here are the steps:

 

//import from spartacus  
import {
  WindowRef,
from '@spartacus/core';
 
//constructor in your component/service  
constructor(
      protected winRefWindowRef,
     ) {}
 
 
const window = this.winRef.nativeWindow;
const document = this.winRef.document;
 
//use it like below 
console.log( window.location.href);
 
//use it like below 
const formHTMLFormElement = this.winRef.document.querySelector('form#loginForm');
 
 
 
 
 
 
 

Comments

Popular posts from this blog

Hybris / SAP Commerce Cloud Groovy Scripting Job to Generate CSV/Excel Reports and copy to Commerce cloud Blob Storage

Emma's dream - a kids story - By Kavya

Hybris/ SAP commerce Cloud: Retry failed/not sent emails due to SMTP connection issue.