How to add headers for an Ionic List? - angularjs

I have an Ionic list like following:
http://i.imgur.com/V0NBvQ3.png
<ion-content>
<ion-list>
<ion-item ng-repeat="x in names|orderBy:'order_id'">
{{ x.order_id + ', ' + x.table_id+', '+x.name+', '+x.phone+', '+x.address+', '+x.remark+', '+changTimetoString(x.ctime)}}
<button onclick="myFunction()">点击这里</button>
</ion-item>
</ion-list>
</ion-content>
I want to add headers for each column, how can I achieve that? thanks.

You are going to want to use the ion grid rather than a list for this. here is a example from a project I made that does what I think you are trying to do:
<div class="list">
<div style="padding: 0px; margin: 0px;" class="item">
<div class="row" style="background-color:#284f9a !important; color: white !important;">
<div class="col left" >
Driver:
</div>
<div class="col center" ng-click="reverse=!reverse; data.metric = 'MPG'">
MPG
<i class="icon" ng-class="{'ion-arrow-down-b': reverse == true && data.metric == 'MPG', 'ion-arrow-up-b': reverse == false && data.metric == 'MPG'}"></i>
</div>
<div class="col right" ng-click="reverse=!reverse; data.metric = 'Miles'">
Miles
<i class="icon" ng-class="{'ion-arrow-down-b': reverse == true && data.metric == 'Miles', 'ion-arrow-up-b': reverse == false && data.metric == 'Miles'}"></i>
</div>
</div>
<div class="row" ng-repeat="item in leaderboardData | orderBy:data.metric:reverse">
<div class="col left">
{{item.Driver}}
</div>
<div class="col center">
{{item.MPG}}
</div>
<div class="col right">
{{item.Miles}}
</div>
</div>
</div>
Then for the alternating row colors add this css:
.row:nth-child(odd) {
background-color: #CCC;
}
.row:nth-child(even) {
background-color: white;
}
looks like this:

You can use either Ionic Grid System, or you can use Ionic List Dividers.
I think the grid will solve you problem.

Related

Angular UI Bootstrap multiple carousel one by one

I am using AngularJS with ui bootstrap module.
1) What I need is my carousel to change its items one by one. I found a code (by other person) but it's only in jQuery.
Codepen code in jQuery
html:
<div class="container">
<h1>Use Bootstrap's carousel to show multiple items per slide.</h1>
<div class="row">
<div class="col-md-12">
<div class="carousel slide multi-item-carousel" id="theCarousel">
<div class="carousel-inner">
<div class="item active">
<div class="col-xs-4"><img src="http://placehold.it/300/f44336/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/e91e63/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/9c27b0/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/673ab7/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/4caf50/000000" class="img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/8bc34a/000000" class="img-responsive"></div>
</div>
<!-- add more items here -->
<!-- Example item start: -->
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/300/8bc34a/000000" class="img-responsive"></div>
</div>
<!-- Example item end -->
</div>
<a class="left carousel-control" href="#theCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
<a class="right carousel-control" href="#theCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
</div>
</div>
</div>
</div>
less CSS:
.multi-item-carousel{
.carousel-inner{
> .item{
transition: 500ms ease-in-out left;
}
.active{
&.left{
left:-3%;
}
&.right{
left:3%;
}
}
.next{
left: 3%;
}
.prev{
left: -3%;
}
#media all and (transform-3d), (-webkit-transform-3d) {
> .item{
// use your favourite prefixer here
transition: 500ms ease-in-out left;
transition: 500ms ease-in-out all;
backface-visibility: visible;
transform: none!important;
}
}
}
.carouse-control{
&.left, &.right{
background-image: none;
}
}
}
jQuery
$('.multi-item-carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
if (next.next().length>0) {
next.next().children(':first-child').clone().appendTo($(this));
} else {
$(this).siblings(':first').children(':first-child').clone().appendTo($(this));
}
});
2) So I want multiple items change one bye one. How to do this in angularJS? Any ideas or directions?

How I can share the value between two pages in ionic v-1

I am trying to add the value of both pages on selection.
It is adding on individual pages. But while I am moving to the next page the Total value comes Zero. I am trying to add pass total added value from one page to another page.
As I search , I found that there is a need to create a service controller to call a global scope value.
<!-- page one view page -->
<ion-content class="search-main padding">
<div class="list card">
<div class="item item-body no-padding stable">
<div class="row no-padding border-bottom" ng-controller="Ctrl3">
<div class="col padding border-right" ng-click="openDateCheckIn()">
<div class="margin-bottom-10" style="color:#0c60ee;"><i class="icon icon-money"></i> Total Value =></div>
</div>
<div class="col padding"><h2 style="text-align:center; margin-top: 3px;">Rs. <b>{{rootSum()}}</b></h2></div>
</div>ass="col padding"><h2 style="text-align:center; margin-top: 3px;">Rs. {{rootSum()}}</h2></div>
</div>
<div ng-controller="Ctrl1">
<div ng-repeat="gender in genders">
<div class="row row-no-padding no-margin padding-important" style="color: #000;">
<div class="col col-70"><i class="ion ion-ios-circle-filled"></i> <span> {{gender.id}}</span></div>
<div class="col col-20"><span>Rs {{gender.value}}</span></div>
<div class="col col-10"><div><label class="search-checkbox item item-checkbox" style="margin: -5px 0px 0px -2px;"><div class="checkbox checkbox-input-hidden disable-pointer-events checkbox-circle"><input id="{{gender}}" type="checkbox" value="{{gender.value}}" ng-checked="selection.indexOf(gender) > -1" ng-click="toggleSelection(gender)" /><i class="checkbox-icon"></i></div><div class="item-content disable-pointer-events" ng-transclude=""></div></label></div>
</div></div>
</div></div>
</ion-content>
<!-- Page two view page -->
<ion-content class="search-main padding">
<div class="list card">
<div class="item item-body no-padding stable">
<div class="row no-padding border-bottom" ng-controller="Ctrl3">
<div class="col padding border-right" ng-click="openDateCheckIn()">
<div class="margin-bottom-10" style="color:#0c60ee;"><i class="icon icon-money"></i> Total Value =></div>
</div>
<div class="col padding"><h2 style="text-align:center; margin-top: 3px;">Rs. <b>{{rootSum()}}</b></h2></div>
</div>
<div ng-controller="Ctrl2">
<div ng-repeat="gender in genders">
<div class="row row-no-padding no-margin padding-important" style="color: #000;">
<div class="col col-70"><i class="ion ion-ios-circle-filled"></i> <span> {{gender.id}}</span></div>
<div class="col col-20"><span>Rs {{gender.value}}</span></div>
<div class="col col-10"><div><label class="search-checkbox item item-checkbox" style="margin: -5px 0px 0px -2px;"><div class="checkbox checkbox-input-hidden disable-pointer-events checkbox-circle"><input id="{{gender}}" type="checkbox" value="{{gender.value}}" ng-checked="selection.indexOf(gender) > -1" ng-click="toggleSelection(gender)" /><i class="checkbox-icon"></i></div><div class="item-content disable-pointer-events" ng-transclude=""></div></label></div>
</div></div>
</div></div>
</div>
</div>
</ion-content>
Controller page --
//Ladies Makeup Party
.controller('Ctrl1', function($scope ,$rootScope) {
$scope.genders=[{
'id':'Krylon Party Makeup', 'value':2000 },
{'id':'Makeup Studio', 'value':2200 },
{'id':'Party Makeup(MAC)', 'value':2500 },
{'id':'Party Mackeup(Airbrush)', 'value':3500 }
];
$rootScope.selection=[];
$scope.toggleSelection = function toggleSelection(gender) {
var idx = $scope.selection.indexOf(gender);
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
else {
$scope.selection.push(gender);
}
};
})
//Ladies Makeup Pre-bridal
.controller('Ctrl2', function($scope ,$rootScope) {
$scope.genders=[{
'id':'Silver', 'value':10000 },
{'id':'Gold', 'value':12000 },
{'id':'Platinum', 'value':16000 }
];
$rootScope.selection=[];
$scope.toggleSelection = function toggleSelection(gender) {
var idx = $scope.selection.indexOf(gender);
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
else {
$scope.selection.push(gender);
}
};
})
// Add total value on select
.controller('Ctrl3', function($scope ,$rootScope) {
$rootScope.rootSum=function(){
var total=0;
for(var i = 0; i < $rootScope.selection.length; i++){
var product = $rootScope.selection[i];
total += (product.value);
}
return total
};
}) *
There are two problems I can see here.
You are initialising $rootScope.selection = [] at every controller, this deletes all previous changes. Initialise it at start of page load inside run block.Use this link to implement run run.
myApp.run(function() {
console.log("app run");
});
You are not transferring selected data to $rootScope.selection variable. You need to append your selected product in rootScope and make sure no item is repeated. Instead of array, I recommend you to use object with 'ids' as attrinute name, this will ensure that no item is repeated inherently.

How to responsive image in ionic from different screen size?

I am creating an ionic app, in that I need to add a four images in my home page in two row and each row has two images. The images size is 296*296.
I have tried the below code,
index.html
<ion-nav-view class="container" >
</ion-nav-view>
Home.html
<ion-view view-title="HOME">
<ion-content>
<div class="row" >
<div class="col-md-6 " id="img1">
<img src="img/hard.png" class="img-responsive " id="img1" >
</div>
<div class="col-md-6" id="img1">
<img src="img/soft.png" class="img-responsive " id="img1">
</div>
</div>
<div class="row" >
<div class="col-md-6 " id="img1">
<img src="img/welcome.png" class="img-responsive " id="img1" >
</div>
<div class="col-md-6" id="img1">
<img src="img/title.png" class="img-responsive " id="img1">
</div>
</div>
</ion-content>
</ion-view>
CSS
#img1{
width: 100%;
height: auto
}
Your ids for div and img are same i.e img1. Change the id and then try. And make width and height important may be some other css overwrites it. Tell me if this works or not.
#img2{
width: 100% !important;
height: auto !important;
}
<div class="col-md-6 " id="img1">
<img src="img/hard.png" class="img-responsive " id="img2" >
</div>
I also got this issue. This code might help to you
HTML
<div class="list card new-feeds wall-post">
<div class="row">
<div class="col">
<div class="item item-image img4">
<img src="img/hard.png">
</div>
<div class="item item-image img4">
<img src="img/soft.png">
</div>
<div class="item item-image img4">
<img src="img/welcome.png">
</div>
<div class="item item-image img4">
<img src="img/title.png">
</div>
</div>
</div>
</div>
css
.wall-post .img4 {
width: 50%;
float: left;
height: 120px;
}
.img4 > img {
height: 100%;
width: 100%;
object-fit: cover;
}

Ionic Scrolling issue - Page scroll breaks when using ion-scroll

I am pretty new to Ionic Framework and the entire hybrid platform.
I have developed a very simple application by using too many tutorials over the internet and the application is working perfectly as expected except the home page.
I have an overall page view that has an ion-content and then there are multiple ion-scroll on the page.
The problem is the scrolling doesn't work as the normal native Android/iOS application.
Can anyone help with this?
Attached below is the full code:
<ion-view ng-init="LoadPage()">
<ion-content ng-show="contentloading" scroll="true">
<ion-refresher pulling-text="Pull to refresh" on-refresh="LoadPage()" >
</ion-refresher>
<div class="row-no-padding">
<div class="row row-no-padding row-center" style="padding-left: 5px;">
<div class="col-33 col-center">
<h5 class="latest-news headingStyle" data-fittext data-fittext-max="12px">Latest News</h5>
</div>
<div class="col col-center">
<ion-slide-box does-continue="true" auto-play="true" show-pager="false">
<ion-slide ng-repeat="item in Slides" ng-click="GoToPost({{item.id}})">
<h4 class="{{FontDetails(1)}}" style="margin-left: 5px;word-break: break-all;white-space:nowrap;overflow:hidden; color:#bb1515;font-size:12px;" ng-bind-html="item.title | unsafe"></h4>
</ion-slide>
</ion-slide-box>
</div>
</div>
</div>
<div class="row-no-padding">
<ion-slide-box does-continue="true" auto-play="true" show-pager="false">
<ion-slide ng-repeat="item in Slides" ng-click="GoToPost({{item.id}})">
<div class="row-wrap">
<div class="col" style="background: url({{item.thumbnail_images.medium.url}}) no-repeat center center; -webkit-background-size: cover;-moz-background-size: cover;background-size: cover;min-height: 200px;height:250px;max-height:300px;z-index: 1;">
</div>
<div style="background:black;position:absolute;opacity: 0.5;filter: alpha(opacity=50);height:auto;bottom:0%;width: 100%;overflow:hidden;z-index:2; vertical-align: top;" class="col">
<h4 class="latest-news-add {{FontDetails(1)}}" ng-bind-html="item.title | unsafe"></h4>
</div>
</div>
</ion-slide>
</ion-slide-box>
</div>
<!-- </div>
</div>-->
<div class="row-no-padding">
<div class="row row-no-padding" style="padding: 5px;">
<div class="col col-33 col-center">
<h5 class="latest-news categoryHeading {{FontDetails(1)}}">{{'Gujarat'| translate}}</h5>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px; overflow: auto;white-space: nowrap; overflow-y: scroll; position: relative;">
<div class="col" >
<ion-scroll direction="x" scroll-outside="true" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="item in gujarat">
<img on-swipe-left="onSwipeLeft()" on-swipe-right="onSwipeRight()" ng-src="{{item.thumbnail_images.medium.url}}" ng-click="GoToPost({{item.id}})" width="150px" height="150px"/>
<div>
<h6 class="{{FontDetails(1, 0)}}" ng-bind-html="item.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
<!--<div class="col">-->
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col col-33 col-center">
<h5 class="latest-news categoryHeading {{FontDetails(1)}}">{{'Politics'| translate}}</h5>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="item in politics">
<img ng-src="{{item.thumbnail_images.medium.url}}" ng-click="GoToPost({{item.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(1)}}" ng-bind-html="item.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<!-- <div class="col col-34" style="text-align: center;margin-bottom: 10px;background-color: firebrick;vertical-align: middle;text-align: center;color:white;font-family: HouseGothicHG23Text-Bold;font-size:1.30em;">
Technology
</div>-->
<div class="col col-center">
<h5 class="latest-news {{FontDetails(1)}} categoryHeading ">{{'Technology'| translate}}</h5>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="item in technology">
<img ng-src="{{item.thumbnail_images.medium.url}}" ng-click="GoToPost({{item.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(1)}}" ng-bind-html="item.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>
</div>
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-list>
<div ng-repeat="item in FooterItems" ng-if="(item.MenuOption !== 'Home' || item.MenuOption !== 'Favorite')" style="margin-bottom: 10px;">
<ion-item style="border: 0px!important;" class="item-stable item item-icon-left home-item-footer item-icon-right {{FontDetails(1)}}" ng-click="toggleGroup({{item.group}},'{{item.link}}')" ng-class="{active: isGroupShown({{item.group}})}">
<i class="icon"><img src="img/{{item.link}}.png" style="width:20px;height:20px;"/></i>
{{item.MenuOption| unsafe | translate}}
<i ng-class="isGroupShown({{item.group}}) ? 'ion-chevron-down' : 'ion - chevron - right'" class="icon" style="font-size:1em;"></i>
</ion-item>
<ion-item class="item-accordion" ng-show="isGroupShown({{item.group}})" style="padding-left:1px;padding-top:1px!important">
<!-- <div class="row row-no-padding">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapper"
ng-repeat="categoryitem in item.items">
<img ng-src="{{categoryitem.thumbnail_images.medium.url}}" ng-click="GoToPost({{categoryitem.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(0)}}" ng-bind-html="categoryitem.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>-->
<div class="row row-no-padding" style="padding: 5px;">
<div class="col">
<ion-scroll direction="x" class="wide-as-needed">
<span>
<span class="wrapperhome" ng-repeat="categoryitem in item.items">
<img ng-src="{{categoryitem.thumbnail_images.medium.url}}" ng-click="GoToPost({{categoryitem.id}})" width="150px" height="150px"/>
<div>
<h6 class = "{{FontDetails(1)}}" ng-bind-html="categoryitem.title | unsafe"></h6>
</div>
</span>
</span>
</ion-scroll>
</div>
</div>
</ion-item>
</div>
</ion-list>
</div>
</div>
</ion-content>
You need to make sure you're declaring the height and width of each <div> you're scrolling. From the ion-scroll docs:
Basic usage:
<ion-scroll zooming="true" direction="xy" style="width: 500px; height: 500px">
<div style="width: 5000px; height: 5000px;
background: url('https://upload.wikimedia.org/wikipedia/commons/a/ad/Europe_geological_map-en.jpg') repeat">
</div>
</ion-scroll>
Note that it's important to set the height of the scroll box as well as the height of the inner content to enable scrolling. This makes it possible to have full control over scrollable areas.

Create Row every after 2 item in Angular ng-repeat - Ionic Grid

I need to create a strcuture as below in my app through ng-repeat.
<div class="row">
<div class="col-50">1</div>
<div class="col-50">2</div>
</div>
<div class="row">
<div class="col-50">3</div>
<div class="col-50">4</div>
</div>
Right now my code is as below:
<div class="row">
<label class="item item-radio col col-50" ng-repeat="a in question.answer">
<input type="radio" name="answers" class="a-{{ a.correct }}" value="{{ a.correct }}" ng-click='ansValue("{{ a.correct }}")'>
<div class="item-content">
<img src="img/ans/{{ a.option }}" />
</div>
<i class="radio-icon ion-checkmark"></i>
</label>
</div>
But in the above code, its just a single row tag that I have. I wan't to somehow get the row tag contain/wrap every 2 items in the loop. What is the best way to achieve this?
Ref: Ionic Grid Doc
I managed to do it using $even.
<div ng-repeat="number in numbers">
<div class="row" ng-if="$even">
<div class="col col-50">{{numbers[$index]}}</div>
<div class="col col-50">{{numbers[$index + 1]}}</div>
</div>
</div>
Here's a working JSFiddle.
The solution from #Patrick Reck is excellent, but it forces you to repeat your code twice,
I suggest this improvement:
<div ng-repeat="number in numbers">
<div class="row" ng-if="$even">
<div class="col col-50"
ng-repeat="num in [numbers[$index],numbers[$index + 1]]">
{{num}}
</div>
</div>
</div>
this way you will write your code one time as if it is a normal ng-repeat
You can add flex-wrap: wrap to class row
http://jsfiddle.net/0momap0n/99/
<div ng-controller="MyCtrl">
<div class="row" style="flex-wrap: wrap">
<div class="col col-50" ng-repeat="number in numbers">{{number}}</div>
</div>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.numbers = [1, 2, 3, 4, 5, 6];
}
I would write it like this, you can increase the $index % 3 to match the number of columns that you would like, this one will create 3 columns ...
<div class="row">
<div class="" ng-repeat="i in range(1, 9)">
<div class="clearfix" ng-if="$index % 3 == 0"></div>
<div class="col">
<h1>{{ i }}</h1>
</div>
</div>
</div>
This solution is using flex-flow and solves this brilliantly:
CSS
.container {
display: flex;
flex-flow: row wrap;
}
.item {
width: 50%;
}
HTML
<div class="container">
<div class="item" *ngFor="let number of numbers">
{{number}}
</div>
Try like below. you can create any number of columns by using the below code. all you need to use the size property of the ionic grid and replace noOfColumns with your what number of columns you want. in this case just use 2 for noOfColumns. it will work like a charm.
Angular grid is based on a 12 column layout with different breakpoints based on the screen size. ref: https://ionicframework.com/docs/layout/grid
<ion-grid>
<ion-row >
<ion-col ng-repeat="n in numbers" size="{{12/noOfColumns}}">
{{ n }}
</ion-col>
</ion-row>
</ion-grid>

Resources