Questions tagged window.location

Explore the latest questions and answers asked by our top developers.

Angular 7 – ngOnInit – window.location.href not working – From HTTPS to HTTP

I have following piece of code in my ngOnInit event. ngOnInit() { let Url = window.location.href.trim().toLocaleLowerCase(); if (Url.startsWith("https://")) { console.log(‘HTTPS’); let NewUrl = Url.replace("https://", "http://"); this.document.location.href = NewUrl; } } My aim is that if Url is having HTTPS then I need to redirect to same Url but with HTTP. But this piece of code […]

By Gulfam
Categorized as angular, ngoninit, redirect, window.location Tagged , , ,

Testing with Testing Library checking content of window.location.href

I´m trying to test the content in a mail pop up window when a button is clicked, using Testing Library. For that i create a method that is rendered in the html template <div > <card (click)="sendMail()" role="button"> <div> ….Something inside the card….. </div> </card> </div> Then the method would be : public sendMail(): void […]

How to mock Location redirect in Jasmine unit test, Angular?

I want to test this function : onLinkClick() { if (this.congratsType === ‘warning’) { this.location.back(); } else { window.location.href = this.urlNol; } } I already try with this: let loc: Location; beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ declarations: [EndFlowComponent], providers: [ { provide: location, useValue: window.history }, ], }).compileComponents(); })); beforeEach(() => { loc = jasmine.createSpyObj(‘Location’, [‘back’]); […]

Please help i have to refresh the component after it has been updated and saved

I am new in angular, I am saving component that has user details successfully but when I go to another tab that calls component it has old data and doesn’t update unless I manually refresh the page. How do I make sure this refreshes automatically without reloading the whole page? I have tried window.location.reload(); but […]

By fulufhelo mudau
Categorized as angular, javascript, window.location Tagged , ,

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us