Injection in Angular 2. How does it work?

Viewed 1819

I've been learning Angular 2 for a few days now. When I read about the Injectable() concept in Angular 2 and try to apply the tutorial's example code in this link : Angular 2 - Dependency Injection, I get a problem.

They said I need to put the annotation @Injectable() on top of the class so that the other classes can inject, like:

import { 
   Injectable 
} from '@angular/core'; 

@Injectable() 
export class appService {  
   getApp(): string { 
      return "Hello world"; 
   } 
}

The problem is that when I drop Injectable(), my app still runs properly. Can someone help me figure out how does injection in Angular 2 work?

2 Answers
Related