1

Dumb question, but I have an application working on the old Angular-cli, that needs to be moved to the new cli, but after all my efforts, still can't get it to work. I am aware that the json parsing is done for me, and the new imports, but still can't seem to get the application to be functional.

This is the old working code before I tweaked with it trying to migrate it and broke it:

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

@Injectable({
  providedIn: 'root'
})
export class JobsService {

  constructor(private http: Http) { }

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

  //add job
  addJob(newJob)
  {
    var headers = new Headers();
    headers.append('Content-Type', 'application/json');
    return this.http.post('http://localhost:3000/api/jobs', newJob,{headers:headers})
        .map(res => res.json());
  }

  //delete
  deleteJob(id)
  {
    return this.http.delete('http://localhost:3000/api/jobs'+id)
        .map(res => res.json());
  }
}

Could someone help me out and perhaps describe to me slightly what I should be doing? Thanks!

3
  • I am aware that the json parsing is done for me, why are you still using json() then? Commented Jun 28, 2020 at 21:49
  • 1
    As I said, this is the code before I went to try to migrate it, so that people could see what it was meant to do. If i was to post the code post migration attempt it wouldn't be functional. Commented Jun 28, 2020 at 22:03
  • 2
    Show us the new code with HttpClient and the errors you get Commented Jun 28, 2020 at 22:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.