Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to import a component without a module

I am wanting to import a component into another component in Angular 4.4.6. This may end up being just a theoretical answer, which is fine. Just figured I would reach out here to see if anyone is doing this. I typically would just create a module for the component etc. etc., but I am really trying to cut out any extra files - trying to avoid file smell.

I have no real code to share, although I am picturing something like this:

@Component({
     selector:'someSelector',
     template:`<html>some html</html>`,
     providers: [someService],
     declarations: [someComponent]  //wanting to do this but I know I can't
})

I do this already bring in outside components in a few places throughout the app, like parent/children communication with @ViewChild() so I get that. Just wondering if this is even possible without making the component I need access to in HTML globally available or if I have to create a module and import it like normal. Thanks!!

like image 314
BSchnitzel Avatar asked Oct 20 '25 06:10

BSchnitzel


1 Answers

Component declarations and providers were supported in Angular 2 RC4. Angular modules were introduced in RC5 and are supposed to fully replace this functionality in modules.

Just wondering if this is even possible without making the component I need access to in HTML globally available or if I have to create a module and import it like normal.

In order to be unavailable globally, a component/directive should be specified in module declarations but not exports. Its selector will be compiled only in components/directives that belong to same module.

like image 130
Estus Flask Avatar answered Oct 21 '25 20:10

Estus Flask



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!