Can I import pages into ion-slides?

Is it possible to import pages(from src/pages your generate) into Slides? I generated a few pages, and I edited the HTML and .ts files for something. I would like to import those pages into ion-slides since the HTML and .ts files of those pages are lengthy and doing all the slides in one page seems a little disorganized.

something like

<ion-slides>
      <ion-slide>
            {{import page 1 here}}?
       </ion-slide>

       <ion-slide>
             {{import page 2 here}}
        </ion-slide>
</ion-slides>

Hello,
principle you should be able to use a page like a custom component. In case of lazy loading you import customcomponet/page into your module file like

{ListPageModule} from 'path to listpage';

and use it in html like your selector is

<app-list [myinput]='bestpageever'></app-list>

Maybe it is better to create a custom component to avoid side effects with multiple ion-content.

Best regards, anna-liebt

Thank you, I may just be doing it wrong since its not working… but i tried it like this

on my slidespage.ts file, I imported page 1 (the custom page i created that i want to import into slides)
import { FirstslidePage } from '../../pages/firstslide/firstslide';

then my html:

<ion-slides>
    <ion-slide>
         <app-list [myinput] = 'FirstslidePage'></app-list>
    </ion-slide>
</ion-slides>

hello,
now we maybe talk about 2 different things. I tought you have created a page and want use this page like a html tag (how you will do it with custom components) in an other page. In this case you must import in a module file (whatever.module.ts, not whatever.ts) the module of your page, add it to @NgModule section and use it as a html tag like your selector describe. See tutorials creating custom components

If you wanna use it as @Input(), then you need to handle it in ts file as @Input(). See tutorials for @Input()

Best regards and confused, anna-liebt

Hi,
Sorry for the confusion.

Yes. So for example, I generated a new page called First. I then added some code on its first.html file and functions on first.ts file. And another page called Second. I want to show these pages in the slides.

On my Home page, I have a button to show slides. Once show slides is clicked, it would open SlidesPage.

On my SlidesPage, I want to import FirstPage and SecondPage. So on the first slide I want to show FirstPage with all the HTML stuff I wrote and its functions in first.ts file.

How can I import FirstPage into SlidesPage like this

<ion-slides>
     <ion-slide>
         (import FirstPage here)
     </ion-slide>
</ion-slides>

Hello,
I guess you are looking for something like this https://stackblitz.com/edit/ionic-lddelj

Unfortunally a 1 to 1 copy of stackblitz code will not work on your machine.

So If you agree that this is what you looking for, then we can go forward. You are on ionic 4 or 3?

Best regards, anna-liebt

Hi,
thank you, yes definitely like this. The home page to be exact, since it slides and it shows 2 different pages. And I’m using Ionic 3

Hello,

okay. The use of a page as tag inside html is the same as for a custom component.
If you take a look to FirstPage.ts, then there is as part of @componet a selector like

@Component({
  selector: 'page-first',
  templateUrl: 'first.html'
})

In your html you use this selector like

<slide>
<page-first></page-first>
</slide>

That an angular componet is known as html tag you need to import the module of your component. In your case you should have a file that is called like first.module.ts. This file should export (at file end) FirstPageModule

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { FirstPage } from './first';

@NgModule({
  declarations: [
    FirstPage 
  ],
  imports: [
    IonicPageModule.forChild(FirstPage )
  ],
})
export class FirstPage Module { }

FirstPageModule is what you need to import in app.module.ts (for eager loading) or in whatever.module.ts (for lazy loading)

import { FirstPageModule } from 'yourPath';

If you use VisualCode or similar, then there are extensions that helps with correct paths.

Last step. Add FirstPageModule to @NGModule imports section of app.module.ts or whatever.module.ts

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    HttpModule,
    BrowserModule,,
    IonicModule.forRoot(MyApp),
FirstPageModule
  ],
.....

The same principle is used for custom components. You can create a custom component and copy all code of ts and html (without <ion-conetn) in it and use it in same way. May better, because I have read anywhere that 2 ion-contents could cause problems.

Best regards, anna-liebt

1 Like

Hello,
Thank you so much for the instructions, they helped a lot. I followed your instructions and imported the FirstPageModule into my Home.module.ts since that is where the slide is. As well as added <page-first></page-first> in home.html.

So when I did that, it was only showing the header of FirstPage. So I thought that whatever was within the <ion-content> wasnt being read. I then removed the ion-content tags in my FirstPage.html and checked the slides in HomePage, which was successfully shown. But maybe bad practice? I noticed that if whatever.html has longer content, the slide only show part of the actual content and it doesnt seem to apply whatever code I have in the page.scss…

Hello,
yes I think creating a custom componet with ionic cli is better practise for using tags in html, because you are preserved of unwanted side effects

ionic generate component

If you wanna use firstPage as page, then you should put ion-content back.

You can put css on first slide, for example <slide style='height=‘600px;’ All other slides has then the same.

Best regards, anna-liebt

Thank you! Will try using a custom component.

Quick question though, how come when I have the ion-content in my html pages, the actual content doesnt show up when I import the page in ion-slide? It just shows a blank page and the header, which is not within the ion-content tags on the html files.

Hello,

if you take look to the stackblitz example, I have put css on the first slide. If you remove it, ion conetnt seems to collapse and shows a tiny scrollbar. So I do not know what it is doing. If you are interested, then you can take a look to ionics github page and see what they are doing. Happy searching :slight_smile:

Best regards, anna-liebt

thank you for the help!