我試圖接口導出一個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