我创建了一个公共模块和另外两个使用公共模块的模块。我从公共模块导出了一些组件,并在另一个组件中导入了公共模块。但是当我尝试在两个模块的路由中使用组件时,我无法自动使用它,并且必须从公共模块的路径显式地导入组件。这对模块独立性构成了一个问题。我该如何解决这个问题?
CommonsModule --> UsersModule (URouting)
CommonsModule --> ReportingModule (RRouting)
我无法访问URouting和RRouting中的导出组件,直到我明确地从CommonsModule路径获取它们。我已从CommonsModule
导出组件import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { CommonModule } from '@angular/common';
import { LoginCommonComponent } from './components/login/login.component';
import { ErrorComponent } from './components/error/error.component';
import { AutocompleteComponent } from './components/autocomplete/autocomplete.component';
@NgModule({
declarations: [LoginCommonComponent, ErrorComponent, AutocompleteComponent],
imports: [
BrowserModule,
FormsModule,
HttpModule,
CommonModule
],
exports: [LoginCommonComponent, ErrorComponent, AutocompleteComponent],
providers: [],
bootstrap: []
})
export class AppCommonsModule { }
用户模块
导入模块
imports: [
BrowserModule,
FormsModule,
HttpModule,
CommonModule,
AppCommonsModule,
adminrouting
],
在路线中我必须做这样的事情:
import {UsersComponent} from '../components/main/main.component';
import {LoginComponent} from '../components/login/login.component'
import {ErrorComponent} from '../../commons/components/error/error.component';
const usersRoutes: Routes = [
{path: 'shop', component: UsersComponent, children: [
{path: '', component: HomeComponent},
{path: 'login', component: LoginComponent},
{path: '**', component: ErrorComponent}
] }
];
这是我的问题
import {ErrorComponent} from '../../commons/components/error/error.component';