Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
757 views
in Technique[技术] by (71.8m points)

angularjs - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...