У меня есть угловой модуль рецепта. Он объявляет и экспортирует компонент рецепта.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RecipeComponent } from './recipe/recipe.component';
@NgModule({
declarations: [
RecipeComponent
],
imports: [
CommonModule
],
exports: [
RecipeComponent
]
})
export class RecipeModule { }
Структура модуля рецептов также содержит страницу рецептов (множественное число), на которой будет отображаться несколько рецептов. Однако, когда я помещаю компонент рецепта в HTML-разметку страницы рецептов, я получаю сообщение об ошибке
core.js:15724 ERROR Error: Uncaught (in promise): Error: Template parse errors:
'app-recipe' is not a known element:
1. If 'app-recipe' is an Angular component, then verify that it is part of this module.
2. If 'app-recipe' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<ion-content>
Если я не включу RecipeModule в импорт recipes.module внутри подкаталога страницы (закомментированные строки генерируют ошибку, раскомментирование их устраняет ошибку)
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
//import { RecipeModule } from '../../recipe/recipe.module';
import { IonicModule } from '@ionic/angular';
import { RecipesPage } from './recipes.page';
const routes: Routes = [
{
path: '',
component: RecipesPage
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
// RecipeModule,
RouterModule.forChild(routes)
],
declarations: [RecipesPage]
})
export class RecipesPageModule {}
Включение родительского модуля в дочерний модуль мне кажется рекурсивным включением. Это правильный способ сделать это, или это будет иметь побочные эффекты в будущем? Есть ли лучший способ сделать это?
Структура папок:
[-] --- src
|
[-] -- app
|
[-] -- recipe
|
[-] -- recipe
|
( the recipe component files)
|
[-] -- recipes
|
(recipe page with its own module}
|
-- recipe.module.ts
|
-- app.module.ts