Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query string parameter in ui-router urls?

I have these states:

.state('quotes', {   abstract: true,   url: '/quotes' }) .state('quotes.new', {   url: '/new',   templateUrl: 'views/quote-form.html',   controller: 'QuoteFormCtrl' }) .state('quotes.new.customer', {   url: '?customer',   templateUrl: 'views/quote-form.html',   controller: 'QuoteFormCtrl' }) 

When I hit the URL /quotes/new?customer=123 the ?customer query string is stripped off, and I am left at the quotes.new state.

What would make most sense to me is just adding a params: ['customer'] to the quotes.new state definition, but that gives me an error complaining that I specify both url and params.

Any examples of what I'm trying to do would be much appreciated.

like image 1000
kbanman Avatar asked Dec 09 '13 01:12

kbanman


People also ask

What are query string parameters in URL?

What are query string parameters? Query string parameters are extensions of a website's base Uniform Resource Locator (URL) loaded by a web browser or client application. Originally query strings were used to record the content of an HTML form or web form on a given page.

How do you query parameters in a URL?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

How do I get query params from my Router?

import ActivatedRoute from '@angular/router'. Inject ActivatedRoute class in constructor. Access queryParams property of ActivatedRoute class which returns an observable of the query parameters that are available in the current URL route.

What is a query string in URL example?

A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, choosing the appearance of a page, or jumping to positions in multimedia content.


1 Answers

You should modify the url string property to include your customer query parameter, like this:

.state('quotes.new', {   url: '/new?customer',   templateUrl: 'views/quote-form.html',   controller: 'QuoteFormCtrl' }); 

Multiple parameters can be added by separating them with an &:

.state('mystate', {   url: '/myState?paramOne&paramTwo   //... }); 

See the docs

like image 189
calebboyd Avatar answered Sep 19 '22 23:09

calebboyd