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 winRef: WindowRef,
) {}
const window = this.winRef.nativeWindow;
const document = this.winRef.document;
//use it like below
console.log( window.location.href);
//use it like below
const form: HTMLFormElement = this.winRef.document.querySelector('form#loginForm');
Comments
Post a Comment