Error importing "Injectable" from Angular

1

File color.service.ts :

import { Injectable } from '@angular/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpModule } from '@angular/http';
import { GLOBAL } from '../services/global';

@Injectable()
export class ColorService {
    public url: string;
    constructor(private http:HttpClient){
        this.url = GLOBAL.url;
    }
    LoadData(data){
        const link = this.http.post( this.url+'colores/listar', data )
        .subscribe(
            resp=> {
              console.log(resp);
            },
            error => {
                console.log("Error", error);
            }
        );
        return link
    }
}

I import it into my component:

import { ColorService } from '../services/color.service';

In the constructor:

private dataService: ColorService

And I call the LoadData () function in my component:

console.log(this.dataService.LoadData(this.colores));

This generates the following error:

Update 1:

By adding it to app.module as suggested by > @jacknavarow , I get the following error:

    
asked by Pablo Contreras 04.10.2018 в 18:22
source

1 answer

4

You have to import your service to the Module of your application, it can be the main one or, exclusively, the module from where you are working:

@NgModule({ imports: [...] , providers: [ ..... , ColorService ], ... })
    
answered by 04.10.2018 / 19:22
source