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>
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 am getting started with angularjs and started working on a simple example. Overall I didn't ran into big challenges so far but this one i couldn't figure out... I have some $scope variables defined like this:
'use strict';
angular.module('portalApp')
.controller('summaryController', ['$scope', function ($scope) {
$scope.todayProduction = '8';
$scope.yesterdayProduction = '20';
$scope.monthlyProduction = '500';
$scope.dockedVessels = '16';
}]);
and this is my view html
<div class="row">
<div class="col-md-3 col-sm-6">
<div class="panel panel-default">
<div class="panel-body">
<div>
<span class="glyphicon glyphicon-stats" style="font-size: 50px;float: right;"></span>
<div>Today's Production</div>
<div style="font-size: 24px;">{{todayProduction}}<span style="font-size: 12px;"> tons</span></div>
</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="panel panel-default">
<div class="panel-body">
<div>
<span class="glyphicon glyphicon-stats" style="font-size: 50px;float: right;"></span>
<div>Yesterdays's Production</div>
<div style="font-size: 24px;">{{yesterdayProduction}}<span style="font-size: 12px;"> tons</span></div>
</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="panel panel-default">
<div class="panel-body">
<div>
<span class="glyphicon glyphicon-stats" style="font-size: 50px;float: right;"></span>
<div>Monthly Production</div>
<div style="font-size: 24px;">{{monthlyProduction}}<span style="font-size: 12px;"> tons</span></div>
</div>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="panel panel-default">
<div class="panel-body">
<div>
<span class="glyphicon glyphicon-stats" style="font-size: 50px;float: right;"></span>
<div>Docked Vessels</div>
<div style="font-size: 24px;">{{dockedVessels}}<span style="font-size: 12px;"> tons</span></div>
</div>
</div>
</div>
</div>
</div>
The problem is that when rendering I see the glyphicon as expected but instead of displaying the variable values I get "{{variableName}}" for all of them.
As a background the sample project I am using was originally for 1.5 version but I'm running a 1.6
Thanks in advance for your help!!
Change {{monthlyProduc tion}} to {{monthlyProduction}} in your html.
I have the next code in Html and AngularJS:
<div class='row'>
<div class='col-md-6' ng-repeat='post in news'>
<div class='post-content'>{{ post.title }}</div>
</div>
</div>
Now, what I need is to push a row with two columns every four posts.
<div class='row'>
<div class='col-md-6'>
<div class='add-content'>Something</div>
</div>
<div class='col-md-6'>
<div class='add-content'>Something</div>
</div>
</div>
How do I do it in AngularJS?
The DOM result what I'm looking for is:
<div class='row'>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<div class='add-content'>Something</div>
</div>
<div class='col-md-6'>
<div class='add-content'>Something</div>
</div>
</div>
<div class='row'>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
...
essentially you need to be using the built in $index which keeps track on the index it is currently on. Every fourth item implies it should be divisible by four. You also need an ng-if statement to determine wether a dom snippet should be added on said item. Also this calls for the use of the ng-repeat-start instead of ng-repeat. Its seldom used but for this purpose it should work. Code below :
<div class='row' ng-repeat-start="post in news" >
<div class='post-content'>{{ post.title }}</div>
</div>
<div class="row" ng-repeat-end ng-if="($index +1 ) % 4 === 0" >
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
<div class='col-md-6'>
<div class='post-content'>POST TITLE</div>
</div>
</div>
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>
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>