我有一個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