Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have the following code on the controller.js and gallery.html

	.controller ('VideoGalleryController', ['$scope', 'videogalleryFactory', function($scope, videogalleryFactory){				
	    //Values of genre searchbox
		$scope.genreOptions = [
	        'Action',
	        'Adventure',
	        'Comedy',
	        'Crime',
	        'Drama',
	        'Historical',
	        'Horror',
	        'Mistery',
	        'Musical',
	        'Romance',
	        'Science Fiction',
	        'Thriller',
	        'Western'
	        ];
		
		//Get dishes from db_movies.json
		videogalleryFactory.getMovies().query(
                function(response) {
                    $scope.movies = response;
                    //Displays nested genres
                    angular.forEach($scope.movies, function(item){
                    	console.log(item.genre);
                    })
                },
                function(response) {
                    $scope.message = "Error: "+response.status + " " + response.statusText;
                });					
	}])
	<div class="row row-content-cards">
		<div class="col-xs-12 col-sm-9">
			<!-- Title filter --> 
			<div class="form-group">
				<label class="col-sm-3 control-label label-title" for="search">Search movie:</label>
				<div class="col-sm-9">
					<input type="text" class="form-control" placeholder="Search movie" ng-model="moviesfilter.title">
				</div>
			</div>
			<!-- Genre filter -->
			<div class="form-group">
				<label for="genre" class="col-sm-3 control-label">Search genre</label> 			                       
				<div class="col-sm-9">
					<select class="form-control"
							multiple 
							chosen 			
							id="genre"
							name="genre" 							
							data-placeholder="Search genres"
							no-results-text="'Could not find that genre'"
							ng-model="???" 
							ng-options="s for s in genreOptions">
							<option value=""></option>
					</select>				
				</div>			
			</div>
		</div>
	</div>
   
	<div class="container-fluid cards-row">
		<div calss="hover-effect">
			<div class="col-sm-6 col-md-4" ng-repeat="movie in movies | filter:moviesfilter as filtText">
				<div class="hover-div">
		    		<div class="thumbnail">
		      			<img ng-src={{movie.cover}} alt="{{movie.alt}}" >
		      			<div class="caption">
		        			<h3>{{movie.title}}</h3>
		        			<span class="badge-space badge" ng-repeat="genre in movie.genre | filter:genre"><strong>{{genre}} </strong></span>
		        			<div class="titlewraptext">
		        				{{movie.plot}}
		        			</div>
		        			<p><a href="#" class="btn btn-primary" role="button">Details</a></p>
		      			</div>
		    		</div>
		  		</div>
			</div>
		</div>	
	</div>
	<p ng-if="filtText.length === 0">
	      <strong>No results found...</strong>
    <p>
</div>

I want on the Filter by genre screenshot once a value is selected the whole movie to be filtered. In this example only "La momia" and "Gladiator" should be displayed.

The json file structure is the following one:

{
  "movies": [
    {
      "title": "La momia",
      "releasedate": "1998-12-31T23:00:00.000Z",
      "length": 125,
      "genre": [
        "Adventure"
      ],
      "plot": "Durante una batalla en Egipto, el legionario Rick O'Connell y un compañero descubren las ruinas de Hamunaptra, la ciudad de los muertos. Algún tiempo después vuelven al mismo lugar con una egiptóloga y su hermano. Allí coinciden con un grupo de estadounidenses, deseosos de correr aventuras, que acabarán provocando la resurrección de la momia de un diabólico sacerdote egipcio que intenta desesperadamente recuperar a su amada.",
      "cast": "Brendan Fraser, Rachel Weisz, John Hannah, Arnold Vosloo, Jonathan Hyde, Oded Fehr, Kevin J. O'Connor, Stephen Dunham, Aharon Ipalé, Tuc Watkins, Omid Djalili, Erick Avari, Carl Chase, Corey Johnson, Bernard Fox, Patricia Velasquez, Ray Donn",
      "cover": "img/film_covers/lamomia.png",
      "downloaddate": "2000-02-04T23:00:00.000Z",
      "alt": "La momia",
      "id": 1
    },
    {
      "title": "Los juegos del hambre",
      "releasedate": "2011-12-31T23:00:00.000Z",
      "length": 143,
      "plot": "Lo que en el pasado fueron los Estados Unidos, ahora es una nación llamada Panem; un imponente Capitolio ejerce un control riguroso sobre los 12 distritos que lo rodean y que están aislados entre sí. Cada distrito se ve obligado a enviar anualmente un chico y una chica entre los doce y los dieciocho años para que participen en los Hunger Games, unos juegos que son transmitidos en directo por la televisión. Se trata de una lucha a muerte, en la que sólo puede haber un superviviente. Katniss Everdeen, una joven de dieciséis años, decide sustituir a su hermana en los juegos; pero para ella, que ya ha visto la muerte de cerca, la lucha por la supervivencia es su segunda naturaleza.",
      "cover": "img/film_covers/losjuegosdelhambre.jpg",
      "cast": "Jennifer Lawrence, Josh Hutcherson, Elizabeth Banks, Woody Harrelson, Donald Sutherland, Stanley Tucci, Liam Hemsworth, Toby Jones, Lenny Kravitz, Wes Bentley, Paula Malcomson, Isabelle Fuhrman, Sandra Ellis Lafferty, Paula Malcomson, Kimiko Gelman, Nelson Ascencio, Brooke Bundy, Amandla Stenberg, Dayo Okeniyi, Leven Rambin, Jack Quaid, Latarsha Rose, Alexander Ludwig, Jacqueline Emerson",
      "downloaddate": null,
      "alt": "Los juegos del hambre",
      "genre": [
        "Action",
        "Drama",
        "Science Fiction"
      ],
      "id": 2
    },
    {
      "title": "Gladiator",
      "releasedate": "2000-04-30T22:00:00.000Z",
      "length": 155,
      "plot": "En el año 180, el Imperio Romano domina todo el mundo conocido. Tras una gran victoria sobre los bárbaros del norte, el anciano emperador Marco Aurelio (Richard Harris) decide transferir el poder a Máximo (Russell Crowe), bravo general de sus ejércitos y hombre de inquebrantable lealtad al imperio. Pero su hijo Cómodo (Joaquin Phoenix), que aspiraba al trono, no lo acepta y trata de asesinar a Máximo.",
      "cover": "img/film_covers/gladiator.jpg",
      "cast": "Russell Crowe, Joaquin Phoenix, Connie Nielsen, Oliver Reed, Richard Harris, Ralf Moeller, Derek Jacobi, Djimon Hounsou, David Schofield, John Shrapnel, Spencer Treat Clark, Tomas Arana, David Hemmings, Tommy Flanagan, Sven-Ole Thorsen, Tony Curran, Giorgio Cantarini, Omid Djalili, Giannina Facio, Michael Sheen",
      "downloaddate": null,
      "alt": "Gladiator",
      "genre": [
        "Action",
        "Adventure",
        "Drama",
        "Historical"
      ],
      "id": 3
    }
  ],
  "series": []
}
share|improve this question
    
All that angular.forEach is going to do is iterate all your objects and display genre. Curious, what are you a) using angular.foreach for instead of just Array.forEach and b) why aren't you using Array.filter instead of just iterating it? – Tim Consolazio 54 mins ago
    
That angular.forEach is just for debugging purposes. It does nothing but displaying in console the genres of each movie – joudaon 48 mins ago
    
Right, but from your question, you're trying to filter? It's early and I haven't had all my coffee, but I don't see any filtering logic. – Tim Consolazio 31 mins ago
    
It is quite difficult to explain. The select box on the "gallery.html" displays a list with different genres. What I want is, once one genre is selected, the whole card (movie) with that genre to be filtered and displayed. In the screenshot only 2 cards should be displayed. Nothing has been developed because all my tries ended with no success, so I don´t know how to do it. – joudaon 20 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.