Reading data.json with HttpClient on Stackblitz?

后端 未结 3 1941
夕颜
夕颜 2021-01-20 06:30

I have a tiny demo and it attempts to read app/data.json using the Angular HttpClient.

const post$:Observable = 

        
3条回答
  •  迷失自我
    2021-01-20 07:25

    i think there are some issues about reading local json in stackblitz it doesn't return plain json just the index.html instead. but another way is mocking a request from local json, you can try:

    import data from './data.json'
    
    ngOnInit(){
      this.getDatas().subscribe(data=>{
        console.log(data)
      })
    }
    
    getDatas():Observable{
      return of(data).pipe(delay(1000));
    }
    

    forked DEMO

提交回复
热议问题