When conducting a search, I prompt the user to enter the value they are looking for in my component.html
.
The data is then sent to the component.ts
using the following code:
<input class="form-control mr-sm-2" #query (keyup.enter)="search(query.value)">
<a class="btn btn-light my-2 my-sm-0" (click)="search(query.value)">Search</a>
In my component.ts
, the function looks like this:
search(query: string) {
if (query !== '') {
window.location.href = 'http://mydomain/result.html?name=' + query;
}
}
I'm puzzled as to why window.location.href
always changes the current URL in the browser when using Firefox Developer Edition, but only sometimes does so in Google Chrome and Firefox Quantum.
Clicking on the button consistently works as expected, but hitting "enter" only triggers the function occasionally in the other two browsers. I'm unsure why this discrepancy occurs and would appreciate any insights or solutions you may have to offer.
- EDIT
Upon debugging, it appears that pressing "enter" doesn't always execute the search
function.