Discussion:
[angular-dart] Is it possible to use a component as if it were a service?
Gonzalo Chumillas
2016-06-25 18:48:09 UTC
Permalink
I would like to make a component available for all other components and
inject it as a service. The following code won't work, since Angular 2
actually creates two instances of ModalPreloader:

// file: app_component.dart
@Component(
selector: 'app-component',
templateUrl: 'app_component.html',
styleUrls: const ['app_component.css'],
// a "Modal Preloader" is at the same time a "directive" and a "service"
directives: const [ModalPreloader],
providers: const [ModalPreloader])
AppComponent {}


// file: app_component.html
// html code...
// Modal Preloader component
<modal-preloader></modal-preloader>


Is it possible to inject an existing component as if it were a service?
This way, I could access that component from any sub-component.
Thanks.
--
You received this message because you are subscribed to the Google Groups "angular-dart" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-dart+***@googlegroups.com.
Visit this group at https://groups.google.com/group/angular-dart.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-dart/eca755ba-4bb1-4f41-83a2-fea530c34092%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Günter Zöchbauer
2016-09-02 05:22:31 UTC
Permalink
Providing a component doesn't do anything meaningful. You'll get an
instance of the component class injected where the @Component()` decorator
is completely ignored.
Rather share a service and use streams to communicate between the component
and all other components and services that want to communicate with it.
Post by Gonzalo Chumillas
I would like to make a component available for all other components and
inject it as a service. The following code won't work, since Angular 2
// file: app_component.dart
@Component(
selector: 'app-component',
templateUrl: 'app_component.html',
styleUrls: const ['app_component.css'],
// a "Modal Preloader" is at the same time a "directive" and a "service"
directives: const [ModalPreloader],
providers: const [ModalPreloader])
AppComponent {}
// file: app_component.html
// html code...
// Modal Preloader component
<modal-preloader></modal-preloader>
Is it possible to inject an existing component as if it were a service?
This way, I could access that component from any sub-component.
Thanks.
--
You received this message because you are subscribed to the Google Groups "angular-dart" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular-dart+***@googlegroups.com.
Visit this group at https://groups.google.com/group/angular-dart.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular-dart/30a55d9d-b4fb-4671-8257-67588d5c02bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...