我是Angular 2的初学者,我正在尝试了解如何从功能模块中导出类,并将其导入到我的主模块中.
当我尝试在打字稿中编译它时,我收到以下两个错误:
app/app.component.ts(11,21):错误TS2304:找不到名称'AddService'.
app/app.module.ts(4,9):错误TS2305:模块'"C:/angular/app/add/arithmetic.module"'没有导出成员'AddService'.
我的树很简单:
/
index.html
package.json
systemjs.config.js
tsconfig.json
typings.json
app/
app.component.html
app.component.ts
app.module.ts
main.ts
add/
add.service.ts
arithmetic.module.ts
Run Code Online (Sandbox Code Playgroud)
有趣的部分如下:
app.module.ts:
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppComponent} from './app.component';
// this next line generates an error from typescript compiler:
// app/app.module.ts(4,9): error TS2305: Module
// '"C:/angular/app/add/arithmetic.module"' has no exported
// member 'AddService'.
import {AddService} from './add/arithmetic.module';
@NgModule({
imports: [BrowserModule],
declarations: [AppComponent, AddService],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import { Component } …Run Code Online (Sandbox Code Playgroud)