Share Services and Data with Angular 2 Dependency Injection

Share this video with your friends

Send Tweet

The Angular CLI generates Services using a simple command. After your Service is generated, you can easily provide and share it to the rest of your application using Angular 2's Dependency Injection. This lesson walks through creating a Service with the Angular CLI then providing it to your application module.

leaf
leaf
~ 8 years ago

I'm getting an error "main.ts:12Uncaught Error: Module build failed: Error:..." after editing 'providers: [MailService],' at app.module.ts, and it didn't automatically imported for me. How can I fix it ?

Cekootje
Cekootje
~ 8 years ago

How comes that when generating a service, ng puts the files right in the app root folder? And creating a component showed that it gets generated inside its own folder. Are there guiding lines for this that ng is following?

vtechmonkey
vtechmonkey
~ 8 years ago

message needs a type of string in mail.service or you get a type error. message : string =You've got mail!;

Javril Bavogui
Javril Bavogui
~ 8 years ago

Not working

Vinícius Mussato
Vinícius Mussato
~ 5 years ago

Had to change the private to public on app.component.ts in order to the example fully work. Its propably related to Aot on angular 8. https://stackoverflow.com/questions/45520838/identifier-refers-to-a-private-member-of-the-component

Nil Hidalgo
Nil Hidalgo
~ 5 years ago

public message = 'You got mail';