0

I am working with the api from The Movie Database. In my Ionic project I was able to make a http request to pull in some data for a movie. However the json object is a nested json object, so I am having some trouble trying to access the genres of a movie:

For the purpose of this question I will display 1 nested json object:

enter image description here

I want to show the information like so -> Genre: Action - Comedy - Drama

My code for the controller is the following:

$scope.init = function(){
        MovieService.getMovieById($stateParams.id).then(function(data){
            $scope.trending_movie = data;
            console.log($scope.trending_movie);

            $scope.genres = data.genres;
            console.log($scope.genres);

        });
    }

If I do this bit of code:

$scope.genres = data.genres;

It just returns met the json object of the genres like so:

enter image description here

The thing is now that I am able to read out the genres but because I access the data with a ng-repeat it will show like this:

enter image description here

How to get the genres on 1 line without having to repeat the word "Genre"?

Here is my html code:

<div ng-repeat="genre in genres">
    <p class="movie-info-p">Genre: {{genre.name}}</p>
</div>

1 Answer 1

1

you should get "Genre:" out of your ng-repeat and if you want your genres to be in the same line, you shouldn't put them in

tag.

There is this solution:

<div> Genre:
 <div ng-repeat="genre in genres">
   <span class="movie-info-p">{{genre.name}}</span>
 </div>
</div>

Another solution is to generate this string in the controller with a for loop and send it to the view

Sign up to request clarification or add additional context in comments.

1 Comment

thanks this works but even with the span its not coming on the same line so I guess i got to tweak it with some css

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.