如何使用Yeomen Generator for Angular框架从Office JS进行Rest API调用? [英] How to make a Rest API call from Office JS using Yeomen Generator for Angular framework?

查看:78
本文介绍了如何使用Yeomen Generator for Angular框架从Office JS进行Rest API调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图引用一个项目 MSFT的Angular Reference Project链接现在,我试图从Angular调用rest API,并试图创建一个singleton服务,但是每当我尝试使用Singleton运行该应用程序时,该应用程序都会失败.

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.

我也无法使用任何Angular-CLI命令,因为也门的Angular解决方案中没有angular-cli.json文件.我如何使用它?

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?

推荐答案

在无法访问目标服务器的情况下解决CORS错误会迫使您采取一些选择.

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

  1. 代理服务器-创建要使用 Access-Control-Allow-Origin:* 进行控制的服务器,然后从您的角度应用向该代理服务器发出请求.然后,代理服务器将转发到目标服务器.

  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.

JSONP-请参阅:什么是JSONP,为什么?是创建的吗?.由于允许您加载远程脚本,因此绕过了CORS限制.加载的结果可以是API调用的结果.您只需要根据自己的喜好对其进行解析.

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.

这篇关于如何使用Yeomen Generator for Angular框架从Office JS进行Rest API调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆