我试图在ng-repeat中运行它,看来ng-show中的条件不起作用。所以我把它移出去了,它似乎仍然无法运行。
表达式显示now_playing但无论我如何编写条件,都不会隐藏或显示元素。
<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>
答案 0 :(得分:2)
我认为您的代码不起作用,因为:
ng-show
movie
创建了控制器别名ng-controller="MovieCtrl as movie"
,但您尚未使用它对于view / html中的访问控制器变量,在您的情况下,您需要为变量名添加别名,例如ng-show
将是:
ng-show="movie.movie_filter === 'now_playing'"
或者您可以从ng-controller
代码中删除别名,您的代码也可以使用。