Ionic 3 refer a new page in app module issue

天涯浪子 提交于 2019-11-30 15:58:43

In ionic 3. Each page is by default setup as a separate module in order to implement lazy loading of pages.

Your page will be declared in new-todo.module.ts.

@NgModule({
    declarations: [
        NewTodo
    ],
    imports: [
        IonicPageModule.forChild(NewTodo)
    ],
    entryComponents: [
        NewTodo
    ]
})

Check out IonicPageModule docs as well as IonicPage.

In your component new-todo.ts page, add the @IonicPage() decorator above the component decorator.

@IonicPage()
@Component({
  selector: 'page-new-todo',
  templateUrl: 'new-todo.html',
})

Also remove all imports to this page outside of the page module. Use the string 'NewTodo' instead of the imported class when pushing the page in NavController. You dont have to declare the page in app.module.ts

$ ionic generate creates a module for lazy-loading pages in ionic3

If you don’t want to take advantage of lazy loading use

$ ionic generate [type] [name] --no-module  

// Do not generate an NgModule for the component

https://ionicframework.com/docs/cli/generate/

In the declaration section of NgModule you have listed a class 'NewTodo' which requires to be A component, or directive, or pipe. Either remove the class name or add corresponding declarator @Pipe/@Directive/@Component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!