我正在尝试添加新模块,以使我的角度应用程序更加模块化和延迟加载。
app.module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule,BrowserXhr } from "@angular/http";
import { LabService } from './lab/lab.service';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { OphistoryModule } from './Ophistory/ophistory.Module' //after adding this module ERROR is thrown
@NgModule({
imports:[
BrowserModule,
HttpModule,
FormsModule,
RouterModule.forRoot([
{path: 'labDetails/:labName',component:LabDetailsComponent},
{path:'showRoboLog/:labName',component:RoboLogComponent},
{path:'',component:LabComponent}
]),
OphistoryModule
],
declarations: [
AppComponent
],
bootstrap:[ AppComponent ]
})
export class AppModule {}
app.component
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import { LabComponent } from './lab/lab.component';
import { LabService } from './lab/lab.service';
@Component({
selector: 'my-app',
template: `
<router-outlet></router-outlet>
`,
providers: [LabService]
})
export class AppComponent {
constructor() {
}
pageTitle: string = 'ABC';
}
添加模块 OphistoryModule 后我遇到的问题是错误消息
我的应用内&#39;不是一个已知元素:
但是当我为新添加的模块的选择器指定相同的名称时,它工作正常。 以下是自定义模块和组件
ophistory.module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'
import { OphistoryComponent } from './ophistory.component'
import {CommonModule} from '@angular/common'
@NgModule({
imports: [RouterModule.forChild([
{path: 'test',component:OphistoryComponent}
]),CommonModule],
declarations:[OphistoryComponent]
})
export class OphistoryModule {}
ophistory.component
import { Component } from '@angular/core'
import { LabService } from '../lab/lab.service'
@Component({
selector:'my-ap',
templateUrl:'./ophistory.component.html'
})
export class OphistoryComponent {
constructor (private _service:LabService){}
}
任何人都可以确认它是角度2中的错误还是您拥有的任何其他解决方案?