Typescript compiler error when importing json file

后端 未结 6 1648
别跟我提以往
别跟我提以往 2020-12-01 15:50

So the code is simple:

calls.json

{\"SERVER\":{
    \"requests\":{
      \"one\":\"1\"
    }
} }

file.ts

import jso         


        
6条回答
  •  猫巷女王i
    2020-12-01 16:00

    For Angular 6 it can work with simple HTTP get call as below
    
    Service
    //interface, could be Array , object 
    export interface ResultJSON{
    
    }
     //Read JSON file for 3DWide
      getJSON() {
        return this.http.get(this.filepathUrl);
      }
    
    Component :import both service and interface and use as below
    resultJSON :ResultJSON;
     this
          .testService
          .getJSON()
          .subscribe((data: ResultJSON) => {
               this.resultJSON= data;
               console.log(this.resultJSON); 
    
    
             });
    

提交回复
热议问题