Tengo una aplicación de la que quiero extraer dos versiones.
La primera es una compilación que contiene toda la aplicación.
La segunda es una aplicación que contiene solo uno de mis módulos. Y también tiene un módulo de enrutamiento separado.
Separé las compilaciones usando el reemplazo de archivos para definir una nueva forma de compilación en angular.json .
Los repuestos son estos:
"fileReplacements": [ { "replace": "projects/my-app/src/environments/environment.ts", "with": "projects/my-app/src/environments/environment.prod.ts" }, { "replace": "projects/my-app/src/app/app.module.ts", "with": "projects/my-app/src/app/app-auth-standalone.module.ts" }, { "replace": "projects/my-app/src/app/app-routing.module.ts", "with": "projects/my-app/src/app/app-auth-standalone-routing.module.ts" }, { "replace": "projects/my-app/src/app/app.component.ts", "with": "projects/my-app/src/app/app-auth-standalone.component.ts" } ] Ahora, cuando ejecuto ng run my-app:auth-standalone:production me da este tipo de errores:
Error: <some-path>/message-bot.component.html:24:34 - error NG8002: Can't bind to 'control' since it isn't a known property of 'app-bot-view-tr ansfer-to-user'. 1. If 'app-bot-view-transfer-to-user' is an Angular component and it has 'control' input, then verify that it is part of this module. 2. If 'app-bot-view-transfer-to-user' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. Si no importo ninguno de los módulos o módulos principales en AppModule , arrojará este tipo de errores.
Intenté agregar NO_ERRORS_SCHEMA y CUSTOM_ELEMENTS_SCHEMA en todos los módulos, pero aún ocurren errores.
Debe cargar/importar correctamente su módulo en ambos módulos de punto de entrada definidos. El error dice que app-bot-view-transfer-to-user no está registrado en el módulo auth-standalone correspondiente. Supongo que ha declarado el componente solo dentro de su app.module .
Debido a los reemplazos, debe asegurarse de registrar también el módulo correspondiente para app-bot-view-transfer-to-user en app-auth-standalone.module.
Si tiene, por ejemplo, la siguiente estructura:
aplicación.módulo.ts:
import AppBotViewTransferToUserComponent from './app-bot-view-transfer-to-user.component'; @NgModule({ declarations: [AppBotViewTransferToUserComponent], }) export class AppModule { }También debe replicar esa estructura dentro de su otro módulo de punto de entrada.
app-auth-independiente.module.ts:
import AppBotViewTransferToUserComponent from './app-bot-view-transfer-to-user.component'; @NgModule({ declarations: [AppBotViewTransferToUserComponent], }) export class AppAuthStandaloneModule { ... }Una mejor manera sería crear un módulo compartido simple que contenga los componentes/servicios compartidos, etc.:
módulo.compartido.ts:
import AppBotViewTransferToUserComponent from './app-bot-view-transfer-to-user.component'; @NgModule({ declarations: [AppBotViewTransferToUserComponent], exports: [AppBotViewTransferToUserComponent] // export the component to make it available in other modules where the Shared module is imported }) export class SharedModule { }Entonces, lo único que queda es borrar tanto su AppModule como su AppAuthStandaloneModule para importar SharedModule; el componente ahora debería poder usarse de ambas maneras:
import SharedModule from './shared.module'; @NgModule({ imports: [SharedModule], }) export class AppModule { ... } @NgModule({ imports: [SharedModule], }) export class AppAuthStandaloneModule { ... }Si esto sigue sin funcionar, necesito más información sobre la configuración, por ejemplo, fragmentos de código.