angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

AngularfirePerformance in main.ts

Open sanderschnydrig opened this issue 3 years ago • 2 comments

I tried to find information about this but couldn't find anything. Is it possible to use AngularfirePerformance to monitor the Angular bootstrapping in main.ts?

Using this code and @angular/fire at version ^7.6.1:

import { AngularFirePerformance } from '@angular/fire/compat/performance';
const performance = inject(AngularFirePerformance)

I'm getting this error:

core.mjs:4768 Uncaught Error: NG0203: inject() must be called from an injection context
    at injectInjectorOnly (core.mjs:4768:1)
    at ɵɵinject (core.mjs:4778:1)
    at 14431 (main.ts:25:27)
    at __webpack_require__ (bootstrap:19:1)
    at __webpack_exec__ (|groupOptions: {}|namespace object:239:1)
    at |groupOptions: {}|namespace object:239:1
    at __webpack_require__.O (chunk loaded:23:1)
    at |groupOptions: {}|namespace object:239:1
    at webpackJsonpCallback (jsonp chunk loading:71:1)
    at main.js:1:59

sanderschnydrig avatar Aug 25 '23 08:08 sanderschnydrig

This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Aug 25 '23 08:08 google-oss-bot

The NG0203 error here is Angular's injection-context rule: inject() can only run inside a constructor, a factory, or an explicit injection context, so calling it at the top level of main.ts will always throw, independent of AngularFire.

This was on the compat performance API in the 7.6.1 era. I'm closing this as a usage issue, but if you hit an injection-context error from within a proper Angular context on a current version, please open a new issue with a minimal reproduction.

armando-navarro avatar Jul 22 '26 20:07 armando-navarro