It seems like the issue is not with your API since you said it is working with cURL.
And since your second console.log() was never executed, my guess is that there is an issue with your request. Maybe you're not including required headers, etc. In your this.http.get(url), you're not including any headers. Does your API require headers to be sent? It would help if you could give your exact cURL command you used because then we could figure out what you're not including in your request. On Thursday, March 23, 2017 at 7:43:26 AM UTC-6, norricorp wrote: > > Hi, > I have a grails rest api server. This returns data when I use curl. > I have used the angular 2 heroes application to display this data. This > was working and then I added authentication and it stopped working. I have > returned to the pre authentication set up and I still get the same errors. > I have logging on grails and I can see that it returns the data. But the > data is not displayed within the browser. > > I have switched on the browser debugging console. Network does not show > any errors but the console shows quite a few. I must admit I do not really > understand what is going wrong from this so hopefully someone can point me > in the right direction. > > > "url is http://centos64:8080/heroes?max=15" > > An error occurred Object { _body: error, status: 0, ok: false, statusText: > "", headers: Object, type: 3, url: null } > > EXCEPTION: Uncaught (in promise): Response with status: 0 for URL: null > > ORIGINAL STACKTRACE: vendor.bundle.js:59773:13 > > resolvePromise@http://localhost:4200/vendor.bundle.js:98058:31 > resolvePromise@http://localhost:4200/vendor.bundle.js:98043:17 > scheduleResolveOrReject/<@http://localhost:4200/vendor.bundle.js:98092:17 > ZoneDelegate.prototype.invokeTask@ > http://localhost:4200/vendor.bundle.js:97855:21 > NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvokeTask@ > http://localhost:4200/vendor.bundle.js:31513:28 > ZoneDelegate.prototype.invokeTask@ > http://localhost:4200/vendor.bundle.js:97854:21 > Zone.prototype.runTask@http://localhost:4200/vendor.bundle.js:97744:28 > drainMicroTaskQueue@http://localhost:4200/vendor.bundle.js:97991:25 > ZoneTask/this.invoke@http://localhost:4200/vendor.bundle.js:97929:25 > vendor.bundle.js:59774:13 > > Unhandled Promise rejection: Object { _body: error, status: 0, ok: false, > statusText: "", headers: Object, type: 3, url: null } ; Zone: angular ; > Task: Promise.then ; Value: Object { _body: error, status: 0, ok: false, > statusText: "", headers: Object, type: 3, url: null } undefined > vendor.bundle.js:97978:13 > > Error: Uncaught (in promise): Response with status: 0 for URL: null > Stack trace: > resolvePromise@http://localhost:4200/vendor.bundle.js:98058:31 > resolvePromise@http://localhost:4200/vendor.bundle.js:98043:17 > scheduleResolveOrReject/<@http://localhost:4200/vendor.bundle.js:98092:17 > ZoneDelegate.prototype.invokeTask@ > http://localhost:4200/vendor.bundle.js:97855:21 > NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvokeTask@ > http://localhost:4200/vendor.bundle.js:31513:28 > ZoneDelegate.prototype.invokeTask@ > http://localhost:4200/vendor.bundle.js:97854:21 > Zone.prototype.runTask@http://localhost:4200/vendor.bundle.js:97744:28 > drainMicroTaskQueue@http://localhost:4200/vendor.bundle.js:97991:25 > ZoneTask/this.invoke@http://localhost:4200/vendor.bundle.js:97929:25 > > Here is the code in the service module. Note that the second log message > does not show. > > getHeroes(): Promise<Hero[]> { > const url = `${this.heroesUrl}?max=15`; > console.log("url is " + url) > return this.http.get(url) > .toPromise() > .then(response => { console.log("response is " + > response.json()); response.json() as Hero[] } ) > .catch(this.handleError); > } > > > Regards, > John > -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
