am new to angularjs.
I want to change the text of single button within ng-repeat after successful POST request.
html code
<div class="row req-content-container" ng-show="selectedTopic">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 create-immediate-meeting-list-container" align="center" ng-repeat="item in allKOL">
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<img class="profile-image-small" ng-src="{{imagesrc}}{{item.photo}}">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3" valign="middle">
<div class="row"><b><span class="pull-left">{{item.firstName}} {{item.lastName}}</span></b><br></div>
<div class="row"><b>Speciality</b><br>{{item.speciality}} </div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<div class="row"> </div>
<div class="row"><b>Location</b><br>{{item.city}}</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<div class="row"> </div>
<div class="row"><b>Convenient Hours</b><br>{{item.fromAvailable}} to {{item.toAvailable}}</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<button type="button" class="btn margin-top-10 request-button-style" ng-click="sendRequest(item.id)">{{sendRequestButtonStatus}}</button>
</div>
</div>
</div>
From controller, am setting the button text to "Send Request" initially and i want it to show "awaiting Request" after successful POST request, but doing this all the buttons text are changing to "awaiting Request". I tried to sort it out but couldn't, can i get any help..
Controller
RequestAMeetingService.immediateMeetWithDoctor(payload, function (result) {
if(result.success) {
$localStorage.immediateMeetingID = result.data.data.meeting;
console.log($localStorage.immediateMeetingID);
console.log(result.data.data);
$scope.closeThisDialog();
$scope.sendRequestButtonStatus = "Awaiting Request";
AlertService.addSuccess(result.data.data.message);
}
else
{
AlertService.addError(result.data.data.err);
}
})
In that case , you have to define a buttons array , with the initial text as Send Request.
var buttonArray = ["Send Request"]; // array should match your ng-repeat length
Modify your ng-click method of your button such that it sends $index as the second argument.Then in your success modify the text according to index.
$scope.buttonArray[index] = "Awaiting Request";
This should be your html
<div class="row req-content-container" ng-show="selectedTopic">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 create-immediate-meeting-list-container" align="center" ng-repeat="item in allKOL">
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<img class="profile-image-small" ng-src="{{imagesrc}}{{item.photo}}">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3" valign="middle">
<div class="row"><b><span class="pull-left">{{item.firstName}} {{item.lastName}}</span></b><br></div>
<div class="row"><b>Speciality</b><br>{{item.speciality}} </div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<div class="row"> </div>
<div class="row"><b>Location</b><br>{{item.city}}</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-3">
<div class="row"> </div>
<div class="row"><b>Convenient Hours</b><br>{{item.fromAvailable}} to {{item.toAvailable}}</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
<button type="button" class="btn margin-top-10 request-button-style" ng-click="sendRequest(item.id, $index)">{{ buttonArray[$index] }}</button>
</div>
</div>
Related
I create add-to-cart app. I need each col in a row to display like it's mentioned col-lg-4 col-md-2 col-sm-6. But it's displayed in a column (Maybe it doesn't work because I added ng-repeat? And this style is the same for every item?
<h2 class="title">{{title}} <i class="em em-shopping_bags"></i></h2>
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-2 col-sm-6">
<div class="card" style="width: 18rem;" ng-repeat='item in itemsArray'>
<img class="card-img-top" ng-src={{item.img}} alt="Card image cap">
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text">{{item.name}}</p>
<p class="price">{{ item.price | currency }}</p>
<i class="em em-shopping_trolley"></i> Add to cart <span class="number">{{ item.quantity }}</span>
</div>
</div>
</div>
</div>
</div>
I receive a json object via an api rest. I want to change the content of my page when the number of places recieved from json = 0.
i have this JSON format :
{
date:"2016-06-30T01:01:01"
id:5
places:[]
}
{
date:"2016-06-30T01:01:01"
id:5
places:
{place: 57}
{
date:"2016-06-30T01:01:01"
id:5
places:
{place: 57}
{place: 58}
{place: 59}
{place: 60}
}
my controller Angular :
$scope.LoadAllSpots = function () {
SpotConfigurationService.GetListSpots(function (datas) {
$scope.CAMs = datas;
console.log(datas);
angular.forEach($scope.CAMs, function (value, Key) {
if (value.places.lenght == 0) {
$scope.ActiveAjoutPlace = false;
}
});
}
my html page :
if place recievied from json = 0 i display the first row else i display the other: have you an idea please
<div class="row " ng-show="ActiveAjoutPlace">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" ng-if="#ViewBag.IsLeft">
<div class="ImgCamera col-lg-6 col-md-6 col-sm-6 col-xs-6 ">
</div>
</div>
</div>
<div class="container">
<div class="row " ng-show="!ActiveAjoutPlace">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 ListPlace ">
<div class="PlaceNumber">
<div class="input-group input-group-left SelectStyle">
<select class="form-control">
<option>place 124</option>
</select>
</div>
</div>
<div class="row RowPicto">
<div class="SvgPicto col-lg-2 col-md-2 col-sm-2 col-xs-2">
<img src="#Url.Content(" ~/Resources/Common/pic_handicap.svg ")" />
</div>
<div class="SvgPicto col-lg-2 col-md-2 col-sm-2 col-xs-2">
<img src="#Url.Content(" ~/Resources/Common/pic_Elec_car.svg ")" />
</div>
<div class="SvgPicto col-lg-1 col-md-1 col-sm-1 col-xs-1">
<img src="#Url.Content(" ~/Resources/Common/pic_moto.svg ")" />
</div>
</div>
<div class="row RowPicto">
<div class="SvgPicto col-lg-1 col-md-1 col-sm-1 col-xs-1">
<img src="#Url.Content(" ~/Resources/Common/car.svg ")" />
</div>
<div class="SvgPicto col-lg-1 col-md-1 col-sm-1 col-xs-1">
<img src="#Url.Content(" ~/Resources/Common/pic_famille.svg ")" />
</div>
<div class="SvgPicto col-lg-1 col-md-1 col-sm-1 col-xs-1">
<img src="#Url.Content(" ~/Resources/Common/pic_GPL_car.svg ")" />
</div>
</div>
<br/>
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 ">
<button value="ToggleContent"click="toggleContent()">Supprimer</button>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6" ng-if="!#ViewBag.IsLeft">
<div class="ImgCamera col-lg-6 col-md-6 col-sm-6 col-xs-6 ">
</div>
</div>
</div>
First of all it's not json because in json format name property and property should be string.
And it should contain , after }
So if I understand correctly you display some data gathered from rest API call and you assign it to $scope.CAMs and if I understand you want to display two different divs if $scope.CAMs is empty or not, right?
You can just use ng-if directive like so:
<div ng-if="CAMs.length > 0"> There is data </div>
<div ng-if="CAMs.length == 0"> CAMs is empty </div>
However $scope.CAMs need to be valid object or JSON.
Same with children:
<div ng-if="CAMs.places.length > 0"> There is data </div>
<div ng-if="CAMs.places.length == 0"> CAMs is empty </div>
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 working with the code below and trying to determine what makes the cols stack on one another. The code looks fine in desktop view, but when I look at it on mobile, the last two col-xs-12 stack together right on top of one another. Is there a break code to make it put a hard return between the two col's in mobile viewing?
<div class="panel panel-default">
<div class="panel-body2">
<div class="row vertical-align">
<div class="col-xs-6 col-sm-3">
<h5><small>Saturday<br>
</small>Feb. 13</h5>
</div>
<div class="col-xs-6 col-sm-3 text-right">
<h5><small>TCU<br>
</small>Horned Frogs</h5>
</div>
<div class="hidden-xs col-sm-3 text-left">
<img src="http://www.wvusports.com/content/images/graphics/logos/TCU.png" width="45">
</div>
<div class="col-xs-12 col-sm-3 text-center">
<span class="label label-warning"><i class="fa fa-ticket"></i> ON SALE SOON</span>
<div>
<img class="hidden-xs" style="padding-top:2px" src="http://www.wvusports.com/content/images/graphics/logos/Big12.png" width="25">
</div>
</div>
<div class="col-xs-12">
<div class="alert alert-success" role="alert">Family Day - $70</div>
</div>
</div>
</div>
</div>
I'm trying to apply ng-repeat to the cols here marked with the class "company". I'm unable to do so because "row" breaks the sequence in between.
I need to show over 1000+ such companies. How should I proceed?
<div class="row">
<div class="col-sm-6 col-xs-12 company">
<small>Users</small>
<small>Followers</small>
</div>
<div class="col-sm-6 col-xs-12 company">
<small>Users</small>
<small>Followers</small>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-xs-12 company">
<small>users</small>
<small>Followers</small>
</div>
<div class="col-sm-6 col-xs-12 company">
<small>users</small>
<small>Followers</small>
</div>
</div>
Try
<div class="row" ng-repeat="i in getNumber(1000)">
<div class="col-sm-6 col-xs-12 company">
<small>users</small>
<small>Followers</small>
</div>
<div class="col-sm-6 col-xs-12 company">
<small>users</small>
<small>Followers</small>
</div>
</div>
In controller
$scope.getNumber = function(num) {
return new Array(num);
}
If you are trying to repeat the .company element, then you should apply the ng-repeat on the .company element.
<div class="row">
<div class="col-sm-6 col-xs-12 company" ng-repeat="i in getNumber(1000)">
<small>users</small>
<small>Followers</small>
<small>...</small>
</div>
</div>
If you are worried about .col-sm-6 not wrapping to the next row for the 3rd+ elements, bootstrap and the browsers are smart to wrap them to the next line. See JSFiddle here - http://jsfiddle.net/s0x7v41p/1/.