angulartypescriptoffice-jsoffice-js-helpers

How to make a Rest API call from Office JS using Yeomen Generator for Angular framework?


I have tried to refer a project Angular Reference Project Link from MSFT and now i am trying to call a rest API from Angular and i am trying to create a singleton service, but whenever i try to run the application with Singleton the application fails.

Also i cannot use any Angular-CLI commanda as there is no angular-cli.json file present in the Yeomen solution for Angular. How can i work with it?


Solution

  • Solving CORS errors without having access to the destination server forces you into a few options.

    1. Proxy server - create a server you DO control with Access-Control-Allow-Origin: * and make the request from your angular app to that proxy server. The proxy server will then forward to the destination server.

    2. JSONP - see: What is JSONP, and why was it created? . This bypasses the CORS restriction as you are allowed to load remote scripts. The result of the load can be the result of the API call. You'll just have to parse it to your liking.