preboot / angular-webpack

A complete, yet simple, starter for Angular v2+ using webpack
MIT License
1.29k stars 557 forks source link

http request fails #245

Closed syeddk closed 7 years ago

syeddk commented 7 years ago

Hi Team,

I am trying to make a call to static json using http module, having trouble loading data from JSON using http. Also tried with API call still no luck. Any help is appreciated.

syeddk commented 7 years ago

Even I tried with Observables, guys need help here

Foxandxss commented 7 years ago

I am the sole maintainer of this repository and I also have a dayjob to attend. A little patience.

syeddk commented 7 years ago

@Foxandxss , Thank you

hijoncon commented 7 years ago

@syeddk you can put your json file under public folder. And you can call it /filename.json

Other option: you can create a get call under webpack dev server. Via app.use then you can filter either req.method

syeddk commented 7 years ago

Hi @hijoncon, Thank you for the reply. I will be a little more clear with my issue, please have a look at the scenario.

Here is my code

rs.service.ts (Service)
---------
getRulesets (): any {
       this.http.get('/rulesets.json').map((res:Response) => res.json());  
}
rs.component.ts (Component)
------------------
 this.rulsetService.getRulesets().subscribe(content => this.staticJsonData = content);

And getting an issue mentioned below image

What am I doing wrong?

ollwenjones commented 7 years ago

You need to make sure that rulesets.json is in a folder which is in/with other statically served assets.

syeddk commented 7 years ago

Thanks @ollwenjones ,

Now i am getting 'undefined'. Even i am getting for REST API calls as well can any one help me out.

mcescalante commented 7 years ago

@syeddk do you still need help with HTTP services with Angular? If so, post your latest code here and I can try to help you debug it and make it work. Otherwise, I am going to close by the end of the day