feat: inject non-annotated tokens as values#45
feat: inject non-annotated tokens as values#45vojtajina wants to merge 1 commit intoangular:masterfrom
Conversation
|
One problem with your example, though I'm not sure it's something to mitigate, but just something that peoples need to know. If |
|
@Alxandr that's a good point, you would have to inject |
|
There is a discussion about this PR at https://groups.google.com/forum/#!topic/angular-dev/sN4cxlqHtKE Without this feature, we might provide additional module that users would have to load to enable this. Something like https://gist.github.com/vojtajina/0a3a59f28ea9b3b5cef0 |
|
@vojtajina or |
If a token is an object or a non-annotated function/class and there is no other provider defined for this token, the default provider returns the value instead of calling it.
This is helpful for injecting third-party code (without instantiating it) that is not annotated. Eg. Node's native modules:
```js
var fs = require('fs');
@Inject(fs.readFile)
class Foo {
constuctor(readFile) {}
}
```
Fixes angular#30
BREAKING CHANGE:
This means that every function/class (that should be called/instantiated) has to be annotated with `@Inject`, even if it takes no arguments.
e46889e to
e4c8659
Compare
|
I must say that I don't thin the injector.bind(fs.readFile).toValue(fs.readFile); is very intuative. If the @Provider syntax will be replaced by the bind syntax then it might make sense. (Part of the confusion is the existing javascript function.bind method). |
|
Is there any update on this pr? |
If a token is an object or a non-annotated function/class and there is no other provider defined for this token, the default provider returns the value instead of calling it.
This is helpful for injecting third-party code (without instantiating it) that is not annotated. Eg. Node's native modules:
Fixes #30
BREAKING CHANGE:
This means that every function/class (that should be called/instantiated) has to be annotated with
@Inject, even if it takes no arguments.See how templating and expressionist needs to be refactored:
angular/templating#35
angular/expressionist.js#13