之前在使用ionic3的ionicPage(懶加載)方式開發(fā)App時,自定義組件,并且在組件中使用ionic3的組件時,報錯 is not a known element。
仔細(xì)想了下,原來是使用懶加載時,每個單獨的頁面都有一個對應(yīng)的module.ts文件,引入了components.module.ts(import了所有的組件,并且輸出),當(dāng)時在components.module.ts中我們并沒有引入IonicModule的依賴,所以導(dǎo)致在組件中使用ionic的組件時,并未識別出此element。
解決方案:
- components.module.ts文件中引入IonicModule。
import { IonicModule } from 'ionic-angular';
- components.module.ts中裝飾器(@NgModule)中的導(dǎo)入IonicModule,這樣便可以使用ionic3的組件了。
@NgModule({
...
imports: [IonicModule],
...
})