I'm trying to integrate my countries.service into my pricing.module and utilize it within the list-pricing component of that module. However, I encountered a circular dependency issue. https://i.sstatic.net/iNepg.jpg
This is how my module looks like
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { PricingRoutingModule } from './pricing-routing.module';
import { DetailsPricingComponent } from './details-pricing/details-pricing.component';
import { ListPricingComponent } from './list-pricing/list-pricing.component';
@NgModule({
declarations: [DetailsPricingComponent, ListPricingComponent],
imports: [
CommonModule,
PricingRoutingModule,
],
})
export class PricingModule { }
https://i.sstatic.net/xFnAp.jpg
Here is the list-pricing component from my module
import { Component, OnInit } from '@angular/core';
import { Post } from 'src/app/Interfaces/post';
import { CountriesService } from 'src/app/services/countries.service';
@Component({
selector: 'app-list-pricing',
templateUrl: './list-pricing.component.html',
styleUrls: ['./list-pricing.component.css'],
})
export class ListPricingComponent {
result:Array<Post>;
constructor(private service:CountriesService) { }
ngOnInit(): void {
this.service.getCountries().subscribe(data=>
{
console.log("hello")
this.result=data;
})
}
}
https://i.sstatic.net/UKR34.jpg Pricing-routing.module content
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { DetailsPricingComponent } from './details-pricing/details-pricing.component';
import { ListPricingComponent } from './list-pricing/list-pricing.component';
const routes: Routes = [
{ path: '', component: ListPricingComponent },
{ path: 'detailsPricing', component: DetailsPricingComponent },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class PricingRoutingModule {}
https://i.sstatic.net/RUnHg.jpg Error Encountered: https://i.sstatic.net/DqJYx.jpg
UPDATE !! I managed to resolve the issue by switching the syntax from @Injectable({ provideIn:....}) in the service to using providers [] in my module instead. Still uncertain about the difference between them though.