中文 | English |
---|
- Angular dependency injection standalone version
- The usage method is completely consistent with Angular's dependency injection
- No transformer required
- 0 dependencies
- Remove Decorator
@Injectable()
=>static injectOptions={}
@Inject() xx
=>xx=inject()
@Optional()
=>xx=inject(token,{optional:true})
JS
/TS
Support
- Angular 18.0.0
- Create a first level dependency injector with
Injector.create
import { Injector, inject } from 'static-injector';
class Main {
child = inject(Child);
}
class Child {
output() {
return 'hello world';
}
}
let injector = Injector.create({ providers: [Main, Child] });
const instance = injector.get(Main);
console.log(instance.child.output());
-
injection-js
belongs to dynamic dependency injection and is a version used before Angular5. Currently no longer updated -
The two are basically interchangeable (the details need to be adjusted)
-
Support the use of
inject
during construction
- The original use of
@Injectable()
to pass parameters has been changed tostatic injectOptions={}
. If there are no parameters, there is no need to set them - Originally,
@Optional
,@SkipSelf
,@Self
, please use the second pass parameter ofinject
instead
- Partially conducted unit testing to ensure that most functions are functioning properly
- Because most of the code itself is extracted from Angular, stability is definitely guaranteed
- Currently, the synchronization logic has been refactored and modified using
@code-recycle/cli
to ensure consistency with the official version ofangular