我有以下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註釋,它都是正確的。有人可以在我這裏做錯了什麼?