我试图接口导出一个NgModule申报出口并在编辑器(Visual Studio代码)已经收到此错误:[ts] 'MyInterface' only refers to a type, but is being used as a value here.
一个接口不能在角度2模块中导出?
下面是示例代码编辑-1:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MaterialModule } from '@angular/material';
import { MyInterface } from './my.interface';
import { MyService } from './my.service';
@NgModule({
imports: [ CommonModule, FormsModule, MaterialModule.forRoot() ],
declarations: [ MyInterface],//<- this is causing the message
exports: [ MyInterface],
providers: [ MyService ]
})
export class MyModule { }
我发现的一个解释部分in the answer to this post:“因为接口在运行时被TypeScript清除”。 我目前正在将我的应用重构为功能模块,因此我现在无法对其进行测试:只能通过从'./mypathto/my.interface'导入来使用接口吗?
发布您的代码。导出和导入接口在这里工作得很好。 –
你想在哪里使用它?作为提供者? '我尝试在NgModule声明中导出一个接口'你是什么意思? – yurzui
查看文档https://angular.io/docs/ts/latest/guide/dependency-injection.html#!#typescript-interfaces-aren-t-valid-tokens – yurzui