我有一个angular-cli应用程序,我也创建了一个模块作为npm包。这是结构:Angular import npm模块不起作用
--otherModule
--other-module.module.ts
--index.ts
--package.json
index.ts:
export { OtherModule } from './other-module.module';
其他-module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';;
@NgModule({
declarations: [ OtherComponent ],
imports: [
CommonModule
],
})
export class OtherModule {
}
运行NPM链接后我试图用这个模块在我的角度cli应用是这样的:
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 {
}
但后来我发现了以下错误:
Unexpected value 'OtherModule' imported by the module 'AppModule'. Please add a @NgModule annotation.
好像装饰不工作或东西。有任何想法吗?
你能否提供other-module.module.ts? – JEY
是的,我更新了答案 – ng2user