Issue
I'm not expert about Angular so probably I'll ask something very trivial.
Useful info about my system (obtain by the command ng --version
) are reported below:
Angular CLI: 13.2.0
Node: 16.13.2
Package Manager: npm 8.6.0
OS: linux x64
My question is about the code which defines a component. I suppose that the name of my component is events
, so I execute the following command in a terminal:
ng generate component events
Previous command generates 4 files and in particular it creates the file events.component.ts
.
Inside the file there is the declaration of the following class:
export class EventsComponent {
...
}
Why do I have to use the export
keyword before the class
keyword?
What is it for?
Solution
This is not related to Angular, but to Typescript. If you want to use code (e.g. a class) in another .ts
file, you have to first export it from your source file.
If you don't need to import it like import {EventsComponent} from '.events.component'
somewhere in your project, you also don't need to export it before. Nevertheless this is not the case for angular components, since they should be used anywhere else (e.g. in a module).
Answered By - Fabian Strathaus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.