0

I have an Angular 2 app that retrieves stock quotes using a URL like http://host/stocks?symbol=AAPL

On page load, a default symbol is fetched and the url reflects this. But, if I enter a symbol the page's the input field and then click the "Get Quote" button, the results are fetched, but the url still reflects the default symbol. How do I get the url to update after fetching a new symbol? Thanks

3
  • 1
    you'll need to add your code here for fetching and displaying the default symbol. Commented May 2, 2017 at 23:23
  • Are you activating a route when the user clicks the Get Quote button? That would change the URL. Commented May 2, 2017 at 23:23
  • No, I don't activate the route, I just fetch the quote data. Won't activating the route cause the page to reload? Commented May 4, 2017 at 2:05

1 Answer 1

3

May be you can use Location service to change url:

 /**
  * Changes the browsers URL to the normalized version of the given URL, and pushes a
 * new item onto the platform's history.
 */
 go(path: string, query: string = ''): void {
  this._platformStrategy.pushState(null, '', path, query);
 }
Sign up to request clarification or add additional context in comments.

1 Comment

What's the type of this._platformStrategy?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.