0

I'm new to angular and I have some questions about services in angular. In some examples the documentation used **export ** before class export and in some codes it used the class with out export no Export. I would appreciated if some one help me to understand its difference completely.

I was trying to inject my service but after I imported it I got the "its not exported" error and it messed up my mind to completely understand each ones usage.

2
  • 3
    You'll need to export. The no export example is wrong. I recommend the new docs angular.dev if you're starting out too Commented Dec 16, 2023 at 0:41
  • Please have a look at this post: stackoverflow.com/q/51183230/12759949 Commented Dec 16, 2023 at 9:42

1 Answer 1

1

You discovered a typo in their documentation where they forgot to add the export keyword before the class name of the service. Any time you want to use a class in another file you have to export it in order for it to be available for other files to import. Seeing that service files are intended to be shared classes you'll want to export them.

With that being said, it's not mandatory to always export your classes, interfaces, types, functions etc. You just won't be able to use them outside of the file you define them in which in some cases you may not need to use them anywhere else which is perfectly fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.