Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Angular component doesn't inject service

I'm trying to follow the MEAN stack tutorial building a todo-list and I ran into problem that my component, where I inject my service doesn't work and I don't have any error messages. Any ideas why?

task.service.ts

import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()

export class TaskService{
   constructor(private http:Http){
     console.log('Task service initialized...'); //this part works
}

getTasks(){
   return this.http.get('http://localhost:3000/api/tasks')
            .map(res => res.json());
}
}

tasks.component.ts

 import { Component } from '@angular/core';
 import {TaskService} from '../../services/task.service';

 @Component({
   moduleId: module.id,  
   selector: 'tasks',
   templateUrl: 'tasks.component.html',
 })

 export class TasksComponent { 

 constructor(private taskService:TaskService){
      this.taskService.getTasks()
        .subscribe(tasks => {
          console.log(tasks);
        });
}
}

app.module.ts

 import { NgModule }      from '@angular/core';
 import { BrowserModule } from '@angular/platform-browser';
 import { HttpModule } from '@angular/http';
 import { AppComponent }  from './app.component';
 import { TasksComponent } from './components/tasks/tasks.component';


 @NgModule({
   imports:      [ BrowserModule, HttpModule ],
   declarations: [ AppComponent, TasksComponent ],
   bootstrap:    [ AppComponent ],

})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import {TaskService} from './services/task.service';

@Component({
  moduleId: module.id,
  selector: 'my-app',
  templateUrl: 'app.component.html',
  providers: [TaskService]
})
export class AppComponent  { }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!