Ionic 3 refer a new page in app module issue

前端 未结 3 456
你的背包
你的背包 2021-01-03 07:05

I generated a new page in ionic 3 using the generate command. When I try adding it to the app module it throws the following error,

Uncaught Error: Unexpecte         


        
3条回答
  •  孤街浪徒
    2021-01-03 07:47

    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

提交回复
热议问题