angular - Error occuring while reading json file in angular2 -


i trying read config.json file in angular2 service below-

load() {     return new promise((resolve, reject) => {         this.http.get('./config.json')             .map(res => res.json())             .subscribe((env_data) => {                 console.log('env_data: ' + env_data);                 this._env = env_data;                 }); } 

this contains list of key , value pairs of application configuration settings. structure of config.json file this-

{   "env": "development" } 

but, on calling load method of angular2 service, receiving below error-

core.umd.js:3462 exception: unexpected token < in json @ position 0errorhandler.handleerror @ core.umd.js:3462next @ core.umd.js:6924schedulerfn @ core.umd.js:6172safesubscriber.__tryorunsub @ subscriber.ts:238safesubscriber.next @ subscriber.ts:190subscriber._next @ subscriber.ts:135subscriber.next @ subscriber.ts:95subject.next @ subject.ts:61eventemitter.emit @ core.umd.js:6164onerror @ core.umd.js:6388onhandleerror @ core.umd.js:6263zonedelegate.handleerror @ zone.js:236zone.runtask @ zone.js:157zonetask.invoke @ zone.js:335 core.umd.js:3467 original stacktrace:errorhandler.handleerror @ core.umd.js:3467next @ core.umd.js:6924schedulerfn @ core.umd.js:6172safesubscriber.__tryorunsub @ subscriber.ts:238safesubscriber.next @ subscriber.ts:190subscriber._next @ subscriber.ts:135subscriber.next @ subscriber.ts:95subject.next @ subject.ts:61eventemitter.emit @ core.umd.js:6164onerror @ core.umd.js:6388onhandleerror @ core.umd.js:6263zonedelegate.handleerror @ zone.js:236zone.runtask @ zone.js:157zonetask.invoke @ zone.js:335 core.umd.js:3468 syntaxerror: unexpected token < in json @ position 0     @ json.parse (<anonymous>)     @ function.json.parse (http.umd.js:188)     @ response.body.json (http.umd.js:1166)     @ mapsubscriber.eval [as project] (config.service.ts:18)     @ mapsubscriber._next (map.ts:79)     @ mapsubscriber.subscriber.next (subscriber.ts:95)     @ xmlhttprequest.onload (http.umd.js:1497)     @ zonedelegate.invoketask (zone.js:265)     @ object.oninvoketask (core.umd.js:6233)     @ zonedelegate.invoketask (zone.js:264)errorhandler.handleerror @ core.umd.js:3468next @ core.umd.js:6924schedulerfn @ core.umd.js:6172safesubscriber.__tryorunsub @ subscriber.ts:238safesubscriber.next @ subscriber.ts:190subscriber._next @ subscriber.ts:135subscriber.next @ subscriber.ts:95subject.next @ subject.ts:61eventemitter.emit @ core.umd.js:6164onerror @ core.umd.js:6388onhandleerror @ core.umd.js:6263zonedelegate.handleerror @ zone.js:236zone.runtask @ zone.js:157zonetask.invoke @ zone.js:335 subscriber.ts:241 uncaught syntaxerror: unexpected token < in json @ position 0     @ json.parse (<anonymous>)     @ function.json.parse (http://localhost:61007/js/@angular/http/bundles/http.umd.js:188:58)     @ response.body.json (http://localhost:61007/js/@angular/http/bundles/http.umd.js:1166:29)     @ mapsubscriber.eval [as project] (http://localhost:61007/app/shared/config/config.service.js:22:50)     @ mapsubscriber._next (http://localhost:61007/js/rxjs/operator/map.js:77:35)     @ mapsubscriber.subscriber.next (http://localhost:61007/js/rxjs/subscriber.js:89:18)     @ xmlhttprequest.onload (http://localhost:61007/js/@angular/http/bundles/http.umd.js:1497:42)     @ zonedelegate.invoketask (http://localhost:61007/js/zone.js:265:35)     @ object.oninvoketask (http://localhost:61007/js/@angular/core/bundles/core.umd.js:6233:41)     @ zonedelegate.invoketask (http://localhost:61007/js/zone.js:264:40) 

please suggest me how avoid error , reading key value pairs json file.

i using angular2 final 2.0.0 vs2015 ide.

check network pannel recieve json, because

unexpected token < in json @ position 0

hints response html page, 404 stub.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -