Thomas Grauer
Thomas Grauer

Reputation: 140

Angular ng-show not running conditional

I was attempting to run this in the ng-repeat and it appears the conditional inside the ng-show is not working. So I moved it out and it still doesnt seem to run.

The expression displays now_playing but will not hide or show the element no matter how I write the conditional.

<div class="container" ng-controller="MovieCtrl as movie" ng-init="loadMovies(movie_filter='now_playing')">
    <div class="row">
        <div class="col-sm-12">
            <h1>Movies</h1>
            <p ng-show"movie_filter === 'now_playing'">{{movie_filter}}</p>
            <form name='filterMovies'>
                <div class="form-group">
                    <select ng-change="loadMovies(movie_filter)" ng-model="movie_filter" name="movie_filter" id="movie_filter">
                        <option selected value="now_playing">Now Playing</option>
                        <option value="top_rated">Top Rated</option>
                        <option value="popular">Popular</option>
                    </select>
                </div>
            </form>
        </div>

        <div class="col-md-2 col-sm-3 col-xs-6 movies" ng-repeat="movie in movies | limitTo: 18">
            <a href="movie_details.php?id={{movie.id}}"><img src="https://image.tmdb.org/t/p/w300{{movie.poster_path}}" alt="" class="img-responsive"></a>
        </div>
    </div>
</div>

Upvotes: 1

Views: 549

Answers (1)

ivamax9
ivamax9

Reputation: 2629

I think your code isn't working, because:

  1. You have missed an equal operator after ng-show
  2. You have created controller alias movie at this place ng-controller="MovieCtrl as movie", but you aren't using it

For access controller variables in view/html, in your case, you need to append alias to your variable names, as example your ng-show will be:

ng-show="movie.movie_filter === 'now_playing'"

Or you can remove alias from ng-controller tag and your code will work.

Upvotes: 2

Related Questions