You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the decorator @InjectableEnhanced (see above) does not work while Ivy is enabled. The following code snipped causes a runtime error (see "馃敟 Exception or Error").
@InjectableEnhanced()// -> does not work, having Ivy enabledexportclassMyService{constructor(){}}
馃敩 Minimal Reproduction
See error
git clone https://github.com/GregOnNet/ng-9-inject.git temp
cd temp
yarn
yarn start # open localhost:4200, see error in browser console
See it working
Turn off ivy in tsconfig.json
Execute yarn start --open to see it working
馃敟 Exception or Error
core.js:597 Uncaught Error: Angular JIT compilation failed: '@angular/compiler' not loaded!
- JIT compilation is discouraged for production use-cases! Consider AOT mode instead.
- Did you bootstrap using '@angular/platform-browser-dynamic' or '@angular/platform-server'?
- Alternatively provide the compiler with 'import "@angular/compiler";' before bootstrapping.
at getCompilerFacade (core.js:597)
at Function.get (core.js:18078)
at Module../src/app/my.service.ts (my.service.ts:20)
at __webpack_require__ (bootstrap:79)
at Module../src/app/app.component.ts (app.component.ts:1)
at __webpack_require__ (bootstrap:79)
at Module../src/app/app.module.ts (app.module.ts:1)
at __webpack_require__ (bootstrap:79)
at Module../src/main.ts (main.ts:1)
at __webpack_require__ (bootstrap:79)
It worked previously because @Injectable previously had no effect at compilation time. It existed to cause TypeScript to emit constructor metadata when compiling the class to allow for JIT compilation.
In Ivy, @Injectable is resolved at compilation time like every other Angular decorator, and thus cannot be wrapped (just like none of the other decorators can be wrapped). Sorry :(
The good news is that we'll likely make providedIn: 'root' the default behavior at some point.
thank you for the quick answer.
According to our direct conversation I hacked a "custom injectable" instrumenting the internal APIs 傻傻defineInjectable and 傻傻inject .
馃悶 bug report
Affected Package
Is this a regression?
Description
Without Ivy, it is possible to build an abstraction for @Injectable (e.g. for configuring the provider dynamically, enhancing the service class).
The following snippet shows an example how @Injectable can be wrapped.
Using the decorator
@InjectableEnhanced
(see above) does not work while Ivy is enabled. The following code snipped causes a runtime error (see "馃敟 Exception or Error").馃敩 Minimal Reproduction
See error
See it working
tsconfig.json
yarn start --open
to see it working馃敟 Exception or Error
馃實 Your Environment
Angular Version:
Anything else relevant?
The text was updated successfully, but these errors were encountered: