0

I'm trying to load local json file but I keep getting an error:

import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";

@Injectable({
  providedIn: "root"
})
export class SearchService {
  constructor(private http: HttpClient) {}
 getJsonFIle() {

    this.http.get("./configs/dor.json").subscribe(data => {
      console.log(data);
    });
  }
}

This is the error on the browser:

enter image description here

enter image description here

5
  • where are your dor.json placed? Commented Jan 10, 2020 at 14:41
  • src\app\configs\dor.json Commented Jan 10, 2020 at 14:53
  • you need to put it into assets and change the path to the /assets/configs/dor.json Commented Jan 10, 2020 at 14:56
  • or you need to add path "src/configs" into angular.json file in "assets" array Commented Jan 10, 2020 at 15:01
  • 1
    Found the answer here. enter link description here Commented Jan 10, 2020 at 15:02

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.