Module.ts Ionic 2

Asked

Viewed 573 times

1

I updated Ionic 2 and angular, but now when I run a page it automatically creates a module.ts file inside the page folder along with html, scss and ts file, does anyone know how to make the application work? because when I try to load with Ionic serves error appears just not recognizing this module.ts of the created page, someone has some solution?

1 answer

0

This new module file is to use Lazy loading (which from my point of view has GREATLY improved performance).

If you do not want to use Lazy loading and continue with Ionic as it was, simply delete this module file and delete the selector in your HTML @IonicPage which he also puts, then you make your routine of adding the page on app.modules.ts and go on living.

If you want to leave the file and do Lazy loading, do the following:

Leave your file paginaNova.module.ts thus:

import { NgModule } from '@angular/core';
import { NovaPagina} from './NovaPagina';
import { IonicPageModule } from 'ionic-angular'; // ele cria com IonicModule e isso da erro, tem que ser IonicPageModule

@NgModule({
    declarations: [NovaPagina],
    imports: [IonicPageModule.forChild(NovaPagina)],
    exports: [NovaPagina]
})
export class NovaPaginaModule { } //tem que ser assim: nomeDaPaginaModule

No need to import this page into your app.module.ts and even on the pages when calling this new page, just use her name in quotes, then a new page push that was like this

import { NovaPagina } from '../novaPagina';

mInhaFuncao(){
  this.navCtrl.push(NovaPagina);
}

Becomes

mInhaFuncao(){ // Não precisa mais importar a página.
  this.navCtrl.push("NovaPagina");
}

Do this for all project pages and be happy, just create a module for home page and import the IonicPage in the pagina.ts and put it under the @Component. Give a little work, but it’s worth it.

I hope I helped :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.