【问题标题】:Unable to view descriptions of generated docs无法查看生成文档的描述
【发布时间】:2016-07-27 11:00:54
【问题描述】:

虽然我能够从文件系统中提供grunt-ngdocs 自动生成的index.html,但每次我尝试查看我得到的文档中的描述时:

XMLHttpRequest cannot load file:///C:/<file-path> Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource

即使docs/partialsdocs/partials/api 文件夹都是空的。

这是我的grunt-ngdocs 配置

ngdocs: {
       options: {
           dest: 'docs',
           html5Mode: false,
           inlinePartials: true,
           scripts: [
               'bower_components/angular/angular.js',
               'bower_components/angular-animate/angular-animate.js'
           ]
       },
       api: {
           src: ['app/scripts/**/*.js'],
           title: 'Docs'
       }
    }

我做错了什么?

提前谢谢你

【问题讨论】:

    标签: angularjs xmlhttprequest xss ngdoc grunt-ngdocs


    【解决方案1】:

    问题是您必须从服务器运行它。我使用节点 http 服务器 (https://www.npmjs.com/package/http-server)。安装后,只需进入 docs/ 目录并输入“http-server”。您将收到以下消息:

    启动 http-server,服务 ./ 在:http://0.0.0.0:8080

    您现在可以查看给定 URL (http://0.0.0.0:8080) 上的文档

    编辑:

    如果您不想从服务器加载它,您可以在 gruntfile 中将选项 inlinePartials 设置为 true。这就是我所拥有的:

    ngdocs: {
        options: {
            dest: 'docs', 
            title: "Docs",
            inlinePartials: true
        },
        api: {
          src: ['<%= yeoman.app %>/scripts/**/*.js'],
          title: 'API Documentation'
        }
    },
    

    见 (https://github.com/m7r/grunt-ngdocs)

    【讨论】:

    • 感谢您的回答,但事实上我试图避免该解决方案,因为其中一位贡献者说ng-docs could be served via file system;此外,我在一个与我有关的问题中发现了一个关于 grunt serve:dist 的问题:你能告诉我是否可以使用该 Grunt 任务为 ngdocs 提供服务?
    • 我已经检查过是否有其他方法,并且 ngdocs 确实允许您将所有模板内联。这将避免 XMLHttpRequest 错误。检查编辑的答案。
    • 我的问题是我确实在我的 Gruntfile 中有 inlinePartials: true,但我仍然收到 XMLHttpRequest 错误
    • 你知道你有哪个版本的ngdocs吗?自 0.2.8 起才允许内联部分(也许你可以检查 package.json)
    • 顺便说一句,我将 http-server 添加到我的 npm 包中,但我仍然看不到任何内容:ngdocs 的索引页面已正确加载,但是当从左侧导航中选择一个元素时查看它的文档,我进入了控制台 404 的部分
    猜你喜欢
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 2018-06-03
    • 1970-01-01
    • 2019-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多