Note that you don’t have to handle the error case of the API if you don’t want to (one advantage of promises).
This should work in your Angular app, but there’s a chance you may hit a CORS (cross-origin resource sharing) security issue. CORS is a security policy that browsers follow, instructing them to request data only from the same hostname the HTML is served from. There are ways to prevent this, but the best way for a MEAN app to do this is to serve
posts.html from the API server.
This is a good idea for a lot of reasons; namely, it will allow you to use
/api/posts instead of
http://localhost:3000/api/posts in t...
- Chapter 5. Integrating Node with Angular
- from Write Modern Web Apps with the MEAN Stack: Mongo, Express, AngularJS, and Node.js
- Publisher: Peachpit Press
- Released: September 2014
Share this highlighthttp://www.safaribooksonline.com/a/write-modern-web/52321/