Javascript 将自定义模块添加到angular中的父应用程序模块时出错
我正在尝试添加新的模块,以使我的angular应用程序更加模块化,并用于延迟加载 应用程序模块Javascript 将自定义模块添加到angular中的父应用程序模块时出错,javascript,angular,typescript,Javascript,Angular,Typescript,我正在尝试添加新的模块,以使我的angular应用程序更加模块化,并用于延迟加载 应用程序模块 import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { HttpModule,BrowserXhr } from "@angular/http"; import { LabService } from './lab/lab.ser
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 {}
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 {}
应用程序组件
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';
}
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){}
}
有人能确认它是angular 2中的一个bug还是您的任何其他解决方案吗?它肯定不是angular方面的bug。。。我没有看到OphiStoryComponentTest的导入抱歉,这是一个输入错误。我试图删除不需要的详细信息,但由于错误,我忘记了删除它。我没有看到CommonModule导入CommonModule导入CommonModule是必要的?我已将CommonModule导入ophistory.module,但仍然存在相同的错误。奇怪的是,如果我更改ophistory.component的选择器到我的应用程序(和主app.component中的相同),则不会抛出任何错误。这肯定不是角度方面的错误。。。我没有看到OphiStoryComponentTest的导入抱歉,这是一个输入错误。我试图删除不需要的详细信息,但由于错误,我忘记了删除它。我没有看到CommonModule导入CommonModule导入CommonModule是必要的?我已将CommonModule导入ophistory.module,但仍然存在相同的错误。奇怪的是,如果我更改ophistory.component的选择器到我的应用程序(与主app.component中相同),则不会引发任何错误。