Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4 Angular: Is it possible to have a fixed element in content while using infinite refresher?

Consider a simple Ionic page's content:

<ion-content>

    <ion-refresher slot="fixed">...</ion-refresher>

    <div *ngFor="let item of items">
        ...
    </div>

    <ion-infinite-scroll>...</ion-infinite-scroll>

</ion-content>

I made a Stackblitz to demonstrate this page: https://stackblitz.com/edit/ionic-v4-angular-tabs-nbjk4k

Now I would like to add something with fixed position – let's say <div>Some content</div> – on the top or bottom of the page that is NOT within the ion-header or ion-footer section. Is it possible to fix that div to stick to the top or bottom?

The official advice I found on the Ionic docs and Github was to use slot="fixed" on any element that I would like to fix in the content area.

It somehow does not work for me, maybe there is a conflict with the slot="fixed" of the refresher component.

How can I achieve a fixed element?

like image 307
andreas Avatar asked Oct 17 '19 19:10

andreas


People also ask

Is ionicons 4 broken when used with angular?

Ionicons 4.x provides a web component that you can use to add an icon with <ion-icon name="..."></ion-icon>. Using this web component in an Angular app doesn’t work though, and many developers have reported that Ionicons 4 is broken when used with Angular.

How to suppress the message “ion-icon is not available” in angular?

If 'ion-icon' is an Angular component, then verify that it is part of this module. 2. If 'ion-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. Angular recommends that you add the CUSTOM_ELEMENTS_SCHEMA to your app’s @NgModule.schemas.

What's new in Ionic 4?

With Ionic 4, your app is using Angular, which already comes with some new additions itself. But now Ionic is also using the standard Angular Router in the background. This means, instead of pushing and popping around inside your app, we have to define paths that are aligned with our pages.

Does ionic use angular router?

But now Ionic is also using the standard Angular Router in the background. This means, instead of pushing and popping around inside your app, we have to define paths that are aligned with our pages.


2 Answers

Indeed there was an issue with slot="fixed", Ionic team did some changes for that.

The content(div?) needs to be wrapped in a position:relative wrapper.
Use position:relative in the tag and it should do the thing. For example - <div slot='fixed' style="position:relative">Some content</div>.

Follow this PR for more Info. Hope this helps!!

like image 144
Vinay sharma Avatar answered Oct 19 '22 02:10

Vinay sharma


Link: https://github.com/ionic-team/ionic/issues/17754

There is a bug on slot="fixed". In order for you to make your desired output, you need to put style="position: relative" as per the discussion above.

I created a simple sample for you below:

<ion-content>
<div slot='fixed' style="position:relative">Some content</div>

 <ion-refresher slot="fixed" (ionRefresh)="doRefresh($event)">
  <ion-refresher-content></ion-refresher-content>
 </ion-refresher>

 <div *ngFor="let item of items; let i=index;" class="item">
   Item {{i}}: {{ item }}
 </div>

 <ion-infinite-scroll threshold="100px" (ionInfinite)="loadData($event)">
  <ion-infinite-scroll-content
    loadingSpinner="bubbles"
    loadingText="Loading more data...">
  </ion-infinite-scroll-content>
 </ion-infinite-scroll>
</ion-content>
like image 31
dom.macs Avatar answered Oct 19 '22 02:10

dom.macs