0

I am accessing my data with

$http.get('/games').success(function(response){
    console.log("I got the data i requested");
    $scope.games = response;
})

then using

<tr ng-repeat="game in games | filter:query">
<td><a href="#/game/{{game._id}}">{{game.title}}</a></td>
<td>{{game.genre}}</td>
<td>{{game.developer}}</td>

to display the all the data in a list. If I now require to display a specific game using its ID how do I go about doing this? I have tried $http.get with params with no luck. how can I filter or query the $scope.games or retrieve specific data inside /games with $http.get.

Thank you

4
  • 1
    Is your back-end implemented that way ? Does it consider URL with id ? Commented Apr 16, 2016 at 11:33
  • It seems you don't need to fetch any additional data. Just get a specific element from games array and use it wherever you need it, that depends on what structure you app has. Commented Apr 16, 2016 at 11:36
  • Which router are you using also? Most would use REST APi to retrieve the single item unless you have a service that stores all of them by default. Not really clear what your specific issue is Commented Apr 16, 2016 at 11:41
  • using angular route, yea i need specific elements from $scope.games but I'm struggling to see how to obtain it. Commented Apr 16, 2016 at 11:43

1 Answer 1

2
<select required name="subCategory" ng-model="selectedSubCategoryIdToAdd" ng-change="GetSubCategoryId()" class="form-control" ng-options="subCategory as subCategory.SubCategoryName for subCategory in subCategories | filter : { CategoryId:selectedCategoryId }: true">
                    <option value="">Select SubCategory</option>
                </select>

This is how i did it with my example

For your example it can be done like this

<tr ng-repeat="game in games | filter: {game_id : 1} : true">
Sign up to request clarification or add additional context in comments.

5 Comments

So you filtered in the HTML? How does this work? my data is current stored at localhost:3000/games
I can filter by somthing set in a controller yea? so if i set $scope.gameId = $routeParams.gameId; for example i can then filter: {{gameId}} : true ? allowing it to filter depending on what url is open?
Yes thats right. The variable you want to specify in filter must be there in the $scope of controller
Edit: I sorted it to work with words e.g. filter:{ 'genre': 'FPS'. but I dont know how to filter with {{gameTitle}} which if I call anywhere in the pages gives me the title of the game.
if you can filter with gameId then you should be able to filter with gameTitle as well

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.