50 questions
2
votes
0
answers
70
views
Route level providers - how to provide them in test
I think there is no possibility to provide mock for any route level provided Services. Creation of test routes to override it has no sense when need to test on real routes.
@Injectable()
export class ...
1
vote
0
answers
168
views
Getting Error : NG0203: `inject()` must be called from an injection context > such as a constructor
Getting this error after upgrade Angular Version 14 to 18.
Till version 16 application working fine but in Version 18 it showing error.
It showing error on main.ts file 69 line.
ERROR : NG0203: ...
0
votes
0
answers
302
views
Angular Upgrade v19 Dev Builds Fine but Prod Build Runtime Error NullInjector
We recently upgraded the Angular app to version 19.
Dev build is running fine, but in prod build we are getting the below error.
My prod settings are below in angular.json file
"optimization&...
1
vote
1
answer
51
views
Provide CustomPipe instead of CurrencyPipe
I want to provide CustomPipe instead of CurrencyPipe. Expected to import and use default CurrencyPipe, but it will use CustomPipe instead of it. I use this provider
{
provide: CurrencyPipe,
...
3
votes
2
answers
191
views
Can we remove all the constructor-based injections?
Recently, Angular put in place a migration to replace constructor-based injection with inject function.
In most of the cases, it is straightforward and it clearly has benefits:
// before
@Injectable({ ...
0
votes
2
answers
283
views
Angular 18 Multiple instance of same service
I've:
service DataLoader who read/write data in DB.
service Report who instances DataLoader using inject
standalone component who inject DataLoader and Report too.
At this point, only one instance of ...
0
votes
1
answer
114
views
Angular component with content projection causes incorrect service injection
I have an Angular directive (LevelDirective) designed to determine its level based on its parent's level (i.e. if parent has level 1 => I should have level 2). It uses a standalone LevelService to ...
0
votes
0
answers
46
views
Angular DI can't resolve token for same class from different WEBPACK_IMPORTED_MODULE
I'm using ngx-mat-select-search and it's complaining about missing MatLegacySelect provider that is clearly provided. I started using a dynamic import when this started occuring if that helps. But ...
2
votes
3
answers
2k
views
Recently started a new concept called Interceptor in Angular 17, but I got the error while practice
I tried to implement the interceptor concept in my angular demo project but I'm getting error on httpInterceptor line 7 i.e
`export const httpInterceptor: HttpInterceptorFn = (req, next) => {`
I'm ...
0
votes
1
answer
61
views
Which type of injector injects the ViewContainerRef or ElementRef?
I read several articles about the two types of injector hierarchies in Angular - the ElementInjector and the EnvironmentInjector hierarchies, and what type of dependencies they provide, and how when ...
1
vote
1
answer
539
views
Angular inject Router into CanActivateFn to use in runInInjectionContext
I have a guard that needs to get something async and then decide with that value if a user needs to be redirected with the URLTree.
The code itself is very simple:
export const otapGuard: ...
1
vote
1
answer
601
views
Angular 17 Functional Resolver Unable to Inject Services Into Jest Test Case
Overview
Hi there,
I am in the process of migrating my Angular app from v14 to v17, and one of the tasks that comes with this is replacing the old deprecated Resolver classes with the new ResolverFn ...
1
vote
1
answer
44
views
Unit Test case to mock Behavior Subject in Store
I have created a store to load address detail in behavior subject
@Injectable({
providedIn: 'root'
})
export class AddressStore {
private subjectAddress = new BehaviorSubject<Address[]>([...
2
votes
1
answer
261
views
Functional resolver with two injected services (Angular 15)
In my resolver, I am trying to inject two services, which uses response of one as input for next service call:
export const addressResolver : ResolveFn<Address> = (
route: ...
3
votes
2
answers
3k
views
Angular standalone component and service constructor injection
I'm having problem injecting a service through standalone component's constructor.
Service is defined as Injectable with provider set to root:
@Injectable({
providedIn: 'root'
})
export class ...