I have a list of JSON data that I need to be able to filter by typing a name in. The results should then only display those listings which have that name in the result. It is currently just hiding the other names, and still showing all of the other listings.
How can I set the filter so that when you type in an actors name, it only shows the movie listings that actor is listed in?
This is the markup used to display the listings, as well as the Angular filter code:
<div class="row" ng-repeat="movies in results | filter:genre">
<div class="col-lg-12">
<div class="well well-sm">
<div class="row">
<div class="col-xs-3 col-md-3 text-center">
<img src="" alt="poster"
class="img-rounded img-responsive" />
</div>
<div class="col-xs-9 col-md-9 section-box">
<h2>
{{movies.Name}}
</h2>
<div class="row rating-desc">
<div class="col-md-12">
<span class="glyphicon glyphicon-time"></span>{{movies.Duration}}<span class="separator">|</span>
<span class="glyphicon glyphicon-signal"></span>{{movies.Rank}}<span class="separator">|</span>
<a class="bookMovie" href="http://www.fandango.com/{{movies.Name}}">Book Now!</a>
</div>
</div>
<hr>
<p>
{{movies.Description}}
</p>
<p ng-repeat="actor in movies.Actors | filter:actor" >
<span ng-bind="actor"></span>
</p>
<hr />
</div>
</div>
</div>
</div>
</div>
The JSON and rest of the code can be seen in this plunker:
https://plnkr.co/edit/ZmxaSRg9ir0qlNNtOyCd?p=preview
You can filter by object like this filter:{ Genres: genre, Actors: actor }
<div class="row" ng-repeat="movies in results | filter:{ Genres: genre, Actors: actor }">
plnkr link
Thats because you should put the actor filter in your parent ng-repeat, check below plnkr:
https://plnkr.co/edit/k1JVXL0Cpxysjhn2tNx7?p=preview
<div class="row" ng-repeat="movies in results | filter:actor | filter:genre">
Related
I have a page to display my friends list for our web application. My problem is that I cant restrict the number of friends shown in one row. I have to display 3 friends in each row:
<div class="row" style="padding-left:200px;">
<div ng-repeat="favourite in favouriteData.data.result">
<div class="col-sm-4 col-md-3 col-lg-2">
<div class="fav_image" >
<img ng-src='/assets/images/profilePics/{{favourite.username +"/"+favourite.profilePic}}' style="height:100px;width:100px;"/>
<h4 class="aju_fav">{{favourite.username}}</h4>
<h4 class="aju_fav">{{favourite.city}}</h4>
<h4 class="aju_fav">Un-Favourite</h4>
<div class=" pull-left user_btm_right"> <i class="fa fa-comments"></i> </div>
</div>
</div>
</div>
plz help to resolve the issue
If you want to always display 3 columns per row (independently from the screen width) you can simply use col-xs-4 (enclosing in a <div class="row"> containing ng-repeat):
<div class="row" ng-repeat="favourite in favouriteData.data.result" class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<div class="fav_image">
<img ng-src='http://192.168.1.75/zentiera/assets/images/profilePics/{{favourite.username +"/"+favourite.profilePic}}' style="height:100px;width:100px;"/>
<h4 class="aju_fav">{{favourite.username}}</h4>
<h4 class="aju_fav">{{favourite.city}}</h4>
<h4 class="aju_fav">Un-Favourite</h4>
<div class=" pull-left user_btm_right"> <i class="fa fa-comments"></i> </div>
</div>
</div>
The best way is to use 'limitTo' filter component in ng. Here is documentation
<div ng-repeat="favourite in favouriteData.data.result | limitTo:3">
I am trying to call an API but I get the Not an array error when I load the page. The data from the JSON isn't showing up.
This is the section of the code that has the issue:
<div class="row" style="margin-top: 20px">
<div class="col-sm-6">
<h4>TESTCASES</h4>
<div ng-repeat="school in schools | filter: {selected: '!true'} track by $index">
<span class="list-group-item" ng-click="school.status =!school.status" style="background-color:rgba(115,158,226,1);">{{school.name}}</span>
<span class="list-group-item" ng-if="school.status" ng-repeat="subSchool in school.sub | filter: {selected: '!true'} track by $index" ng-click="select(subSchool)" tooltip= '{{subSchool.name}}, Run Time: {{subSchool.runTime}}'>{{subSchool.name}}</span>
</div>
</div>
<div class="col-sm-6">
<h4>TEST PLAN</h4>
<div class="list-group list-select">
<span class="list-group-item" ng-repeat="school in selected track by $index" ng-click="deselect(school)">{{school.name}}</i></span>
</div>
</div>
</div>
I have a table with an ng-repeat over a function that I want to be rerendered after a user logs in. How do I make a view load the ng-repeat and again to triger the function. Is there a way to make an ng-repeat rerender on a change in the model?
Here is the view, to give an idea why a function is used instead of just looping over a model. The repeat in question is ng-repeat="(index, event) in vm.getEvents(dayObject) track by $index" :
<!-- CALENDAR NAV -->
<div class="calendar-nav">
<div class="prev">
<button class="btn btn-default pull-right" ng-click="vm.goToPrevWeek()" ng-disabled="vm.isCurrentWeek"><i class="glyphicon glyphicon-chevron-left"></i></button>
</div>
<div class="date">
<p class="text-primary text-center">{{vm.weekViewString}}</p>
</div>
<div class="next">
<button class="btn btn-default pull-left" ng-click="vm.goToNextWeek()"><i class="glyphicon glyphicon-chevron-right"></i></button>
</div>
</div>
<!-- END CALENDAR NAV -->
<!-- CALENDAR HEADER -->
<div class="calendar-header">
<div class="weekdate-header date-header day-1 split-{{vm.weekSplit}}" ng-class="{'today': dayObject.isToday}" ng-repeat="(index, dayObject) in vm.calendarDays track by $index">
<div class="date-container"><span class="date">{{dayObject.day}}</span><span class="week-day"> {{dayObject.weekDay}}</span></div>
</div>
</div>
<!-- END CALENDAR HEADER -->
<!-- CALENDAR CONTENT -->
<div class="calendar-content">
<div class="calendar-aside">
<div class="day-hour" ng-repeat="(index, hourObject) in vm.calendarHours track by $index">
<span class="hour">{{hourObject.hour}}</span>
</div>
</div>
<div class="calendar-days">
<div class="calendar-day day-col day-1 split-{{vm.weekSplit}}" ng-class="{'today': dayObject.isToday}" ng-repeat="(index, dayObject) in vm.calendarDays track by $index">
<div class="mobile-day hidden-lg hidden-md hidden-sm">
<div class="date-container"><span class="date">{{dayObject.day}}</span><span class="week-day"> {{dayObject.weekDay}}</span></div>
</div>
<div class="day-hour hour-{{hourObject.number}}" ng-repeat="(index, hourObject) in vm.calendarHours track by $index">
<div class="hour">
<div class="half-hour"></div>
</div>
</div>
<!-- CALENDAR EVENTS -->
<div id="{{event.idName}}" class="event-container {{event.type}}" style="top: {{event.top}}px; left: {{event.left}}%; width: {{event.width}}%; height: {{event.height}}px;"
ng-repeat="(index, event) in vm.getEvents(dayObject) track by $index" ng-switch="event.type">
<div class="buttons" ng-switch-when="">
<div class="amount">{{event.spotsAvailable}}</div>
</div>
<div class="buttons" ng-switch-when="success">
<i class="glyphicon glyphicon-ok-sign"></i>
</div>
<div class="buttons" ng-switch-when="full">
<i class="glyphicon glyphicon-ban-circle"></i>
</div>
<div class="text">
<span class="title">{{event.name}}</span>
<p class="locatie-time hidden-lg hidden-md hidden-sm"> <span>{{event.startsAt | date:'HH:mm' }}</span> - <span>{{event.endsAt | date:'HH:mm' }}</span> </p>
<span class="locatie-info">{{event.formattedAddress}}</span>
</div>
</div>
<!-- END CALENDAR EVENTS -->
</div>
</div>
</div>
<!-- END CALENDAR CONTENT -->
I ended up replacing the function in the ng-repeat with a direct link to the data the function was returning and now the view is updating.
I have a plunker here - http://plnkr.co/edit/AmoiJi8k000OKA6TNdcz?p=preview
I'm using dummy json here - http://myjson.com/4aqlh
I want to display the json content in different parts of the page based on a value in the json
So the stories with a value of Section: "New" will be displayed in one div and 'Old' in another.
This works in the first div where 'New' is dispalyed but in the second div that should only display 'Old', it displays all the stories.
Is there something wrong with the filter or is something to do with the order Angular builds the page.
<div class="container" data-ng-controller="myCtrl">
<div class="row">
<div class="col-sm-6">
<div class="story" data-ng-repeat="story in stories | filter: story.Section='New' " >
{{story.Title}}
{{story.Section}}
</div>
</div>
<div class="col-sm-6">
<div class="story" data-ng-repeat="story in stories | filter: story.Section='Old' ">
{{story.Title}}
{{story.Section}}
</div>
</div>
</div>
</div>
This is how you do filtering with filter
<div class="col-sm-6">
<div class="story" data-ng-repeat="story in stories | filter: {Section:'New'}" >
{{story.Title}}
{{story.Section}}
</div>
</div>
<div class="col-sm-6">
<div class="story" data-ng-repeat="story in stories | filter: {Section:'Old'}">
{{story.Title}}
{{story.Section}}
</div>
</div>
It takes an object syntax. = is an assignment operator. See filter documentation
Specify the expression in the filter explicitly and it will work.
Working plunker: http://plnkr.co/edit/yLIO14rlWdCFKtmg3b3N?p=preview
<div class="container" data-ng-controller="myCtrl">
<div class="row">
<div class="col-sm-6">
<div class="story" data-ng-repeat="story in stories | filter: story: story.Section='New' " >
{{story.Title}}
{{story.Section}}
</div>
</div>
<div class="col-sm-6">
<div class="story" data-ng-repeat="story in stories | filter: story: story.Section='Old' ">
{{story.Title}}
{{story.Section}}
</div>
</div>
</div>
</div>
I would like to use Angular data-binding to dynamically change the date used for Livestamp.
For instance, I would like to make the following dynamic:
<span data-livestamp="1413704094"></span>
by using Angular databinding, something like:
<span data-livestamp="{{item.Date.toISOString}}"></span>
How do I do it? The above code doesn't work.
EDIT:
Here's how it's used:
<div class="panel panel-default messageItems" ng-repeat="item in vm.itemsTop | orderBy:'Id':true" ng-animate="'animate'">
<div class="panel-body">
<div class="media">
<a class="pull-left" href="/People/{{item.User.Username}}">
<img class="media-object"
src="http://mysite/{{item.User.Username}})/avatar"
alt="{{item.User.Username}}" />
</a>
<div class="media-body">
<h4 class="media-heading">
<span ng-bind="item.User.Username"></span>
</h4>
<h6>
posted <span data-livestamp="{{item.Posted.toISOString}}"></span> (<span ng-bind="item.Posted.toUTCString()"></span>)
</h6>
<p class="emojstext">
<span ng-bind="item.Text"></span>
</p>
</div>
</div>
</div>