【发布时间】:2017-06-20 09:30:35
【问题描述】:
我有一个 Angular 应用程序,我还创建了一个模块作为 npm 包。这是结构:
--otherModule
--other-module.module.ts
--index.ts
--package.json
index.ts:
export { OtherModule } from './other-module.module';
other-module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';;
@NgModule({
declarations: [ OtherComponent ],
imports: [
CommonModule
],
})
export class OtherModule {
}
运行 npm link 后,我尝试在我的 AppModule 中使用这个模块,如下所示:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { OtherModule } from 'other-module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
OtherModule
],
providers: [],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
然后我收到以下错误:
模块“AppModule”导入的非预期值“OtherModule”。 请添加@NgModule 注解。
装饰器似乎不起作用或其他什么。有任何想法吗?
【问题讨论】:
-
你能提供 other-module.module.ts 吗?
-
是的,我更新了答案
标签: javascript angular npm