我做了一个定制的angular2(5.0.x)模块,如下所示:
import { GuageService } from './services/guage.service';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GuageComponent } from './guage/guage.component';
@NgModule({
declarations: [GuageComponent],
imports: [
CommonModule
],
providers : [GuageService],
exports : [GuageComponent]
})
export class GuageModule {}我在我的应用程序模块中使用它,像这样:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { DxButtonModule, DxCircularGaugeModule } from 'devextreme-angular';
import { GuageModule } from '@kronsbi/bi-module-template';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
DxButtonModule,
DxCircularGaugeModule,
HttpClientModule,
GuageModule
],
bootstrap: [AppComponent]
})
export class AppModule { }当我尝试启动我的应用程序时,我会得到以下错误。
由模块'AppModule‘导入的意外值'GuageModule’。请添加一个@NgModule注释。
更新
用于主应用程序的tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}GuageModule包的ts配置:{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"stripInternal": true,
"experimentalDecorators": true,
"strictNullChecks": true,
"noImplicitAny": true,
"module": "es2015",
"moduleResolution": "node",
"paths": {
"@angular/core": ["node_modules/@angular/core"],
"rxjs/*": ["node_modules/rxjs/*"]
},
"rootDir": ".",
"outDir": "dist",
"sourceMap": true,
"inlineSources": true,
"target": "es5",
"skipLibCheck": true,
"lib": [
"es2017",
"dom"
]
},
"files": [
"index.ts"
],
"angularCompilerOptions": {
"strictMetadataEmit": true
}
}发布于 2017-11-22 23:18:47
如果您使用的是角5.0,则需要将"annotationsAs": "decorators"添加到包的"angularCompilerOptions"中。Range5引入了新的优化,默认情况下,在编译时删除装饰器,因为它们在运行时不需要。正如您已经发现的那样,这不适用于包。您可以在角5公告博客中了解到这一点,“构建优化器”一段提到了这一点。5.0.0版的角现在可用
我在我的角包中使用这个设置:
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"skipMetadataEmit": false,
"strictMetadataEmit": true,
"annotationsAs": "decorators"
}发布于 2017-11-20 09:39:57
发布于 2017-11-20 09:34:19
请添加"emitDecoratorMetadata":在您的量规模块的compilerOptions of tsconfig.json中为true
https://stackoverflow.com/questions/47331202
复制相似问题