-
Notifications
You must be signed in to change notification settings - Fork 27k
Closed
Labels
area: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerworkaround2: non-obvious
Milestone
Description
Which @angular/* package(s) are the source of the bug?
compiler, core
Is this a regression?
No
Description
import {
Component,
Inject,
Injectable,
InjectionToken,
forwardRef,
} from '@angular/core';
import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';
import 'zone.js'
export const t = new InjectionToken<number[]>('addresses'); //bug, if we change the name of variable to t1, for example, it works
@Component({
standalone: true,
selector: 'a-comp',
template: `A`,
providers: [
{ provide: t, useValue: [1], multi: true },
],
})
export class A {
constructor(@Inject(t) ns: number[]) {
console.log(ns);
}
}
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule, A],
template: `<a-comp />`
})
export class AppComponent {}
bootstrapApplication(AppComponent);
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-starters-6h67j1?file=src%2Fmain.ts
Please provide the exception or error you saw
Error: ASSERTION ERROR: token must be defined [Expected=> null != undefined <=Actual]
at throwError2 (chunk-TNFBICRJ.js?v=aebd17e5:4511:9)
at assertDefined (chunk-TNFBICRJ.js?v=aebd17e5:4507:5)
at bloomHashBitOrFactory (chunk-TNFBICRJ.js?v=aebd17e5:7731:16)
at lookupTokenUsingNodeInjector (chunk-TNFBICRJ.js?v=aebd17e5:7562:21)
at getOrCreateInjectable (chunk-TNFBICRJ.js?v=aebd17e5:7554:19)
at Module.ɵɵdirectiveInject (chunk-TNFBICRJ.js?v=aebd17e5:10585:17)
at NodeInjectorFactory.A_Factory [as factory] (main.ts:22:15)
at getNodeInjectable (chunk-TNFBICRJ.js?v=aebd17e5:7714:38)
at instantiateAllDirectives (chunk-TNFBICRJ.js?v=aebd17e5:11162:23)
at createDirectivesInstances (chunk-TNFBICRJ.js?v=aebd17e5:10761:3)
Please provide the environment you discovered this bug in (run ng version)
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 18.1.2
Node: 20.16.0
Package Manager: npm 10.8.1
OS: darwin x64
Angular: 18.1.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1801.2
@angular-devkit/build-angular 18.1.2
@angular-devkit/core 18.1.2
@angular-devkit/schematics 18.1.2
@schematics/angular 18.1.2
rxjs 7.8.1
typescript 5.5.4
zone.js 0.14.8
Anything else?
No response
BojanKogoj
Metadata
Metadata
Assignees
Labels
area: compilerIssues related to `ngc`, Angular's template compilerIssues related to `ngc`, Angular's template compilerworkaround2: non-obvious