Update URL on dropdown change

1,397 views
Skip to first unread message

levyuk

unread,
Mar 3, 2013, 3:00:33 PM3/3/13
to ang...@googlegroups.com
Does anyone know how I can change the URL based on a dropdown option?

Thanks
Jon

Joshua Miller

unread,
Mar 3, 2013, 3:18:35 PM3/3/13
to angular
Hello!

I'm not sure what you mean by "dropdown", but you can change the URL using the `$location` service: http://docs.angularjs.org/api/ng.$location. Can you be a little more specific on what you want to do or, even better, provide a simple Plunker?

Josh


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

levyuk

unread,
Mar 3, 2013, 3:25:40 PM3/3/13
to ang...@googlegroups.com
Hi
By dropdown I mean a HTML select

Joshua Miller

unread,
Mar 3, 2013, 3:43:09 PM3/3/13
to angular
Ok, no problem - just define an ngModel on your select:

<select ng-model="url">
...
</select>

And you can react to the model change in your controller:

$scope.$watch( 'url', function ( color ), {
  $location.url( url );
});

If you want something more special, check out the docs for select: http://docs.angularjs.org/api/ng.directive:select.

Josh


On Sun, Mar 3, 2013 at 12:25 PM, levyuk <levy...@gmail.com> wrote:
Hi
By dropdown I mean a HTML select

levyuk

unread,
Mar 3, 2013, 3:54:00 PM3/3/13
to ang...@googlegroups.com
Cool idea. I'll give that a go. Thanks

Adam Koch

unread,
May 24, 2013, 2:40:03 PM5/24/13
to ang...@googlegroups.com
This is (like) what I'm doing...
<select ng-model="filters.firstName">
<option value="">All</option>
<option value="John">John</option>
<option value="Puck">Puck</option>
<option value="Steve">Steve</option>
</select>
<select ng-model="filters.lastName">
...
<script>
function Ctrl($scope, $location) {
$scope.$location = $location;

$scope.filters = {"firstName": "", "lastName": ""};
$scope.$watch("filters", function(filters) {
$location.url(filters.firstName || filters.lastName);
}, true);
...
Reply all
Reply to author
Forward
0 new messages