-
Notifications
You must be signed in to change notification settings - Fork 232
di: Provider with useValue doesn't accept const complex data type instances #10
Comments
Current workaround: use |
Could you try this: const displayOptions = const Bar();
@Component(
selector: 'foo',
template: '<div></div>',
providers: const [const Provider(DisplayOptions, useValue: displayOptions)]
) It might be slightly less hacky. The current Angular analyzer/compiler is pretty rudimentary, but we have plans to improve it to include full package resolution. Can update on this soon. |
P3 since there is a workaround. Blocked by #48 |
Just an update: this is still blocked by #48. We have some early work done though towards getting the type information we need to actually resolve the value. |
This is now planned for the 4.0 release. |
This is now unblocked, with caveats:
class Foo {
const Foo();
}
const Provider(Foo, useValue: const Foo()) // OK
class Bar {
static const instance = const Bar._();
const Bar._();
}
const Provider(Bar, useValue: Bar.instance) // NOT OK, we only see "Bar._". This isn't something we can solve in the short-term, but it will make providers more useful for public constructors. I'll give an update when folks are able to start using this externally (initially behind a flag, and hopefully the default for |
Closing since it technically has landed. |
In beta 18, declaring a
Provider
withuseValue
currently fails in the angular transfomer if you use an instance of a complex data type.For example, use the following setup to define a component:
This throws
Invalid argument(s): Incorrect identifier "const Bar()"
And the stack trace is:
The text was updated successfully, but these errors were encountered: