我有以下module
:导入模块到另一个模块访问服务
import { NgModule } from '@angular/core';
import { ActivitiesService } from '../services/activities.service';
@NgModule({
declarations: [],
imports: [ActivitiesService],
providers: [],
bootstrap: [],
exports: [ActivitiesService]
})
export class ActivitiesModule { }
的ActivitiesService
将通过我的应用程序内的不同组件一起使用,所以我决定创建一个为其进口的ActivitiesService
共享模块服务并导出,使其可供其他模块导入。
然后,我创建了一个新module
,该模块将导入上述module
这是如下:
import { NgModule } from '@angular/core';
// Components
import { ProfileComponent } from '../component/profile/profile.component';
// Routing
import { profileRouting } from '../routing/profile-routing';
// Shared << IMPORTED OTHER MODULE HERE
import { ActivitiesModule } from '../../shared/modules/activities.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
// Authentication Guard
import { AuthenticationGuard } from '../../shared/guards/authentication.guard';
@NgModule({
imports: [
profileRouting,
FormsModule,
ReactiveFormsModule,
ActivitiesModule],
declarations: [
ProfileComponent],
providers: [AuthenticationGuard]
})
export class ProfileModule { }
现在在我的ProfileComponent
我有以下声明:
// Services
import { ActivitiesService } from '../../../shared/services/activities.service';
的构造方法ProfileComponent
constructor(private activityService: ActivitiesService) {}
我ngOnInit
方法看起来像这样:
ngOnInit() {
this.activityService.getActivities();
}
然而,当我运行它,并导航到Profile
页我得到错误信息:
Error: Uncaught (in promise): Error: Unexpected value 'ActivitiesService' imported by the module 'ActivitiesModule'. Please add a @NgModule annotation. Error: Unexpected value 'ActivitiesService' imported by the module 'ActivitiesModule'. Please add a @NgModule annotation.
我检查命名约定,托运@ NgModule注释,它都是正确的。有人可以在我这里做错了什么?