I started the studies with angular4, and I'm trying to get the json
return of a simple request through a service
.
But when calling the requesting method, it gives me the following error in my component login.component.ts
:
Property 'subscribe' does not exist on type '() = > void '.
However, running this same method inside my component
it works normal and returns me my json
Below is the code for my service
and my component
:
credentials.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class CredentialsService {
constructor(private http: Http) { }
public getCredentials(){
var url = 'http://luingry.com.br/easyjob/WebServices/angular/login.php';
this.http.get(url)
.map(dados =>{ return dados.json();});
}
}
login.component.ts
import { Component, OnInit } from '@angular/core';
//importando o serviço
import { CredentialsService } from './services/credentials.service';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
constructor(public c: CredentialsService) {}
ngOnInit() {
this.c.getCredentials.subscribe(g =>{
console.log(g);
});
}
}
What can I do to get json
of my request through service
.