I am having problem in http service.
What i tried is this.http.get('http://jsonplaceholder.typicode.com/posts/1') as sample data and it works.
But when I used this.http.get('src/data/employees.json') it shows me 404 (Not Found)
employees.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class EmployeesService {
constructor(private http: Http) {}
getEmployees() {
this.http
.get('src/employees.json')
.map((response) => response.json())
.subscribe((result) => console.log(result));
}
}
app.component.ts
import { Component } from '@angular/core';
import { EmployeesService } from './employees.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
constructor(private employeesService: EmployeesService) {}
ngOnInit() {
this.employeesService.getEmployees();
}
}