How to print a web page in ion-view - angularjs

I am using Ionic Framework for my web application. Each page is displayed using ion-view. I want to print graph (or save it as pdf).
Here is my code,
<ion-view title="Report">
<ion-nav-buttons side="right">
<button menu-toggle="left"class="button button-icon icon ion-navicon"></button>
</ion-nav-buttons>
<ion-content class="has-header">
<b style="padding:10px;">Patient Background Report</b>
<div class="text-center item"><canvas id="line" class="chart chart-line" data="agedata" colours="colours"labels="labels" legend="true" series="series" click="onClick">
</canvas>
<b>Age</b>
</div>
Print
</ion-content>
I using Chrome-browser. When I click on print button , it returns
"print preview failed".
How to print this page?

I was able to get my Ionic app to print by adding the following CSS:
#media print {
.scroll-content {
position: relative;
}
.pane {
position: initial;
}
}
Don't ask me why that works; I just know that it works for me, and I hope it also helps someone else!

I know that i might be a little bit late to the party but I hope that this would help others in future.
The solution for this problem is to overwrite default ionic components styling.
In defaults, some properties could broke our print preview like: position, height, overflow.
It's a must to remember that for printing:
height: 100%,
position: fixed/absolute/relative (in some cases),
overflow: hidden,
are 'the last nail in the coffin'.
None of container should have them set.
For position you can use static, for height use fixed values or just leave an auto option. Always remember to set overflow: visible. Otherwise the thing we want to print could be hidden.
You can also read my short article in order to have a more in depth knowledge on printing ionic based applications: http://blog.primemodule.com/print-style-sheets-in-ionic-framework/

Related

How to make an element specific when using providers in Ionic

After implementing the following pattern, I want, however, for only specific pages to have a unique toolbar or header.
Any idea on how that can be made ? Do I need not to inject the provider and have that page as a standalone ?
I am new to Ionic so please let me know if this situation is not clear enough
My current code is the following
<ion-content class="no-scroll">
<ion-header *ngIf="page.pageName != 'MyPageWithUniqueToolbar'">
<ion-toolbar color="primary" class="sub-header">
<ion-title class="sub-header-titl1">{{ page.ToolbarTitle }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="no-scroll">
<ion-nav class="content-body" [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
</ion-content>
</ion-content>
I tried to put the ngIf above like this but it errors out
<ion-content *ngIf="page.pageName != 'MyPageWithUniqueToolbar'" class="no-scroll">
For that *ngIf to work you must have a variable page defined on all your page components that have this *ngIf. If you only define this on the page that you want to show a different header it will error on all the others that don't have a variable page defined.
A quick fix for this would be to first check if the variable page exists, and then check the value of page.pageName, like below:
<ion-header *ngIf="page && page.pageName != 'MyPageWithUniqueToolbar'">
<ion-toolbar color="primary" class="sub-header">
<ion-title class="sub-header-titl1">{{ page.ToolbarTitle }}</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="no-scroll">
<ion-nav class="content-body" [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
</ion-content>
Remember, you need the page variable defined in the component, e.g.
page = {pageName:'MyPageWithUniqueToolbar'};
Hope it helps
After some more investigation, I found the solution. By replacing ngIf by [hidden], that did the trick, see below :
<ion-nav [hidden]="page.pageName === 'MyPageWithUniqueToolbar'" class="content-body" name="bodyHeader" [root]="state.bodyHeader.current" #bodyHeader swipeBackEnabled="false"></ion-nav>

Prevent column-count breaking inner elements

I am trying to create a responsive image wrap gallery. Each image will have a header. I distribute them using column-count of webkit.
The problem is this: I've specified a container to be "relative". Inside that container, I have an "absolute" header followed by an image. What seems to be happening in some values of column-count is that the header is going to another column and the image in the next. I need them both to be together at all times and I'm surprised why the absolute within relative container is not doing that.
A codepen for reference: http://codepen.io/pliablepixels/full/YwWLzy/
The core image gallery code is:(SO insists I include a code fragment when posting a codepen link, so here goes)
<div style="-webkit-column-count:{{ cols }};-webkit-column-gap:0px;line-height:0px;">
<span ng-repeat="image in images">
<div style="position:relative">
<div class="my_header">Header</div>
<img class="scaled_image" src={{ image.src }} />
</div>
</span>
</div>
Please change the column values and note the header behavior.
How does one solve this? (Note I must use an img tag - can't use background-image)
thanks
Columns
To protect elements from breaking and keep them entirely in a column you can add these properties:
.element {
-webkit-column-break-inside: avoid; /* Chrome, Safari, Opera */
page-break-inside: avoid; /* Firefox */
break-inside: avoid; /* IE 10+ */
}
Your fixed example http://codepen.io/anon/pen/rxMWxa
Header
Such behaviour occurs because you've added line-height:0px to your container div. So you can just return header's line-height value to normal. Fixed that in codepen.
Using line-height sometimes can make headache. Try to use padding like below:
.my_header {
background-color: red;
padding: 2px 4px;
line-height: normal;
}

How to shift the position of badge in ion-tab which is title-only?

I need the badge to come on the top-right of where the text ends, right now it's not like that -
Here is the screenshot of the default implementation :
<ion-tab title="Business" badge="homeBadgeCount" badge-style="badge-assertive" href="#/tab/home">
I have made following changes to make it work :
Created a new CSS class to be used that positions the badge properly:
.business-badge {
right: 32px !important;
}
And used that class inside the html:
Hope it will be useful for someone who is not much familiar with css like me ;)

ngSwipe not working properly

I'm creating a touch screen application for my client using AngularJs. I'm using ngTouch and then the directives ng-swipe-left and ng-swipe-right. I've created a function that should be called when I swipe left and similarly for swipe right.
HTML Template:
<div class="prod-gall" data-ng-controller="getItemDataCtrl>
<ul class="prod-gall-list" data-ng-swipe-left="swipeLeft($event)">
<li data-ng-repeat="i in itemList" >
<figure class="prd-img"> #*<img src={{i.image}} alt="" />*# <img class="figure.prd-img img" src=content/images/movies/m2210521.jpg alt="" />
<figcaption class="prd-nam f5">{{i.title}}</figcaption>
</figure>
<div class="prd-price f5"> {{i.currentprice}} </div>
</li>
</ul>
</div>
I'm seeing the below to problems.
When I swipe in left I could see my function being called but not always, it is working intermittently, I'm unable to find the exact location when it is actually calling the function (however I don't want it to work only for specific location) because it is not that it is working always when I swipe on the same area, it keep on changing.
You see that I'm using the ul - > li ->figure and figcaption - when I try to swipe by touching the li which is container of the figure and figcaption I could see that figcaption i.e., text is being highlighted or selected and if I touch sipw on the image the image clone is being selected instead of swipe. (this may not be related to ngTouch, but not sure)
How can I fix these two issues. Please help.
I was just calling the wrong function, i.e., when I swipe left I was calling the function that I've created for swipe right and vice versa.

Responsive facebook comment box

I've been researching several different ways to force a facebook comment box plug-in to be fluid/responsive/liquid/whatever-we-call-it (just showing the stupidity of names), and all of them work fine. But also, all of them make the plug-in disappear when accessing from Google Chrome.
I'm using this:
.fb-comments, .fb-comments span, .fb-comments.fb_iframe_widget span iframe {
width: 100% !important;
}
Which has the same results (apparently) as:
#fbcomments, .fb-comments, .fb-comments iframe[style], .fb-comments span{
width: 100% !important;
}
Question: How can I fix this strange behavior? (Why does it happen?)
Thanks for your time. Wether you do help me or not, have a nice to-day! :)
this worked for me: Add to the fb-comments div data-width="100%"
<div class="fb-comments" data-href="http://example.com/comments" data-width="100%" data-numposts="5" data-colorscheme="light"></div>
and it will be responsive when you resize the browser.
you can put the fb-comments div inside another div and give that div the width you want.
This is facebook comment part-
<div class="fb-comments" data-href="http://example.com/comments" data-numposts="5" data-colorscheme="light"></div>
Just add this CSS bellow the div-
<style>.fb_iframe_widget span[style]{width:100% !important;}</style>
Just Insert data-width="100%" in the div
<div class="fb-comments" data-width="100%"></div>
You could use data-mobile atribute
<div class="fb-comments" data-href="http://example.com/comments" data-numposts="5" data-mobile="true"></div>

Resources