1

I'm currently using $location in my app so I can send parameters from the address bar to my $http GET request. Like so:

var params = $location.search();
$http.get(url, params).then(function(){
    ...
}

Is it possible to add an ng-click attribute onto an element in my view, so I can pass parameters into the address bar, so I can filter my GET request?

Something like so:

<div ng-click="genre=romance">Romance</div>
<div ng-click="genre=horror">Horror</div>

<div ng-click="year=2012">2012</div>
<div ng-click="year=2011">2011</div>

So when two buttons are clicked the queries chain themselves and url is transformed to: app.com/movies?genre=horror&year=2012, for example.

Is this possible with $location and am I going about this in the right way?

Any help is appreciated. Thanks in advance!

1 Answer 1

1

Search function is both getter and setter. You can e.g. put $location in $scope and then use it like this:

<div ng-click="$location.search('genre','romance')">Romance</div>
<div ng-click="$location.search('genre','horror')">Horror</div>
<div ng-click="$location.search('year','2012')">2012</div>
<div ng-click="$location.search('year','2011')">2011</div>

And modify $http.get:

$http.get($location.absUrl()).then(function(){...}
Sign up to request clarification or add additional context in comments.

Comments

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.