小编Tan*_*may的帖子

从Word Web加载项(Office.Js)进行的API调用不起作用:CORS问题?

朋友们

我正在尝试从Word加载项调用API,并收到“访问被拒绝”错误。我做了一些研究,看来是“跨源资源共享”的原因。

1. Web API

我在“ http:// localhost:61546 / api / ORG_NAMES ” 本地托管Web API 2,并且已启用CORS接受所有来源,请参见下面的WebApiConfig。

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            var cors = new EnableCorsAttribute("*", "*", "*");
            config.EnableCors(cors);

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
Run Code Online (Sandbox Code Playgroud)

2.测试申请

为了测试此API以确保它支持CORS,我已经在下面的页面中创建并托管在localhost:52799 / home.html上,我能够获得预期的响应。我已经在IE 10和Chrome中对此进行了测试。

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function () {
            var obj;
            .support.cors …
Run Code Online (Sandbox Code Playgroud)

ms-word asp.net-web-api asp.net-web-api2 office365api office-js

5
推荐指数
1
解决办法
2718
查看次数

Angular:解析器错误:意外的标记 -、预期的标识符、关键字或字符串

我在我的项目中使用@angular~4.0.0,我以表格形式显示数据并想添加搜索控件。

该代码有效(没有过滤器)

<tr *ngFor="let item of components">
Run Code Online (Sandbox Code Playgroud)

但是当我为过滤器添加以下代码时,它会抛出错误

<tr *ngFor="let item of components | filter-data:compName">
Run Code Online (Sandbox Code Playgroud)

错误 :

Unhandled Promise rejection: Template parse errors:
TypeError: Unable to get property 'toUpperCase' of undefined or null reference ("
            </tr>
        </thead>
        <tr [ERROR ->]*ngFor="let item of components | filter-data:compName">
        <!--<tr *ngFor="let item of componen"): ng:///App/PortalComponents/ComponentList/component-list.component.html@14:12
Parser Error: Unexpected token -, expected identifier, keyword, or string at column 32 in [let item of components | filter-data:compName] in ng:///App/PortalComponents/ComponentList/component-list.component.html@14:12 ("nts | filter-data:compName">
        <!--<tr *ngFor="let item of …
Run Code Online (Sandbox Code Playgroud)

angular-pipe angular

3
推荐指数
1
解决办法
3万
查看次数