Creé rutas con caminos infantiles profundos. Añadí <router-outlet>
a la AdminComponent componente que he envuelto en NgModule. Pero después de actualizar la página recibí este error:
'router-outlet' is not a known element
Tal vez ocurrió porque olvidé importar algún módulo a admin.module.ts
Por favor ayuda. Gracias.
app.routes.ts
export const routes: Routes = [
{
path: '',
component: AppComponent,
children: [
{
path: '',
component: LoginComponent
},
{
path: 'admin',
component: AdminComponent
},
{
path: 'user',
component: UserComponent
},
{
path: 'there',
component: ThereComponent
}
]
}
]
app.module.ts
@NgModule({
imports: [
BrowserModule,
AppRoutes,
FormsModule,
ReactiveFormsModule,
HttpModule,
RouterModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (http: Http) => {
return new TranslateStaticLoader(http, './src/assets/i18n', '.json')
},
deps: [Http]
}),
UserComponentModule,
AdminComponentModule,
LoginComponentModule,
ThereComponentModule,
DashboardComponentModule
],
declarations: [
AppComponent
],
providers: [
FormBuilder
],
bootstrap: [AppComponent]
})
admin.component.ts y admin.module.ts
// admin.component.ts
import {Component} from "@angular/core";
@Component({
selector: 'admin',
template: "<router-outlet></router-outlet>",
})
export class AdminComponent {
constructor() {
}
}
// admin.module.ts
const ADMIN_DECLARATION = [
AdminComponent
];
@NgModule({
imports: [
BrowserModule,
TranslateModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ADMIN_DECLARATION
],
exports: [
ADMIN_DECLARATION
],
providers: [
TranslateService,
FormBuilder
]
})
export class AdminComponentModule {
}
angular
angular2-routing
Станислав П
fuente
fuente
;
Respuestas:
AdminComponent
es parte del módulo internoAdminComponentModule
y no lo ha importado :RouterModule
AdminComponentModule
// admin.component.ts import {Component} from "@angular/core"; @Component({ selector: 'admin', template: "<router-outlet></router-outlet>", }) export class AdminComponent { constructor() { } } // admin.module.ts const ADMIN_DECLARATION = [ AdminComponent ]; @NgModule({ imports: [ BrowserModule, TranslateModule, RouterModule, FormsModule, ReactiveFormsModule ], declarations: [ ADMIN_DECLARATION ], exports: [ ADMIN_DECLARATION ], providers: [ TranslateService, FormBuilder ] }) export class AdminComponentModule { }
fuente
no exportaste el RouterModule.
@NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] })
fuente
Agregar este código
import { provideRoutes} from '@angular/router';
para usted
app.module.ts
Trabajó para mi.
fuente
En su archivo app.module.ts
import { routing } from './app-routing.module'; //and then write within imports @NgModule({ declarations: [ AppComponent, NavbarComponent ], imports: [ BrowserModule, **routing**, EmployeeModule ],
fuente
Esto funciona para mi:
Agregue esquema
[NO_ERRORS_SCHEMA]
en AppModule.fuente
app.module.ts
fuente