【问题标题】:ng-include not working on iOSng-include 在 iOS 上不起作用
【发布时间】:2018-04-04 15:28:06
【问题描述】:

请帮助我解决这个问题,以下代码在 Android 上运行良好,但在 iOS 上运行不正常。它返回错误

XMLHttpRequest 无法加载 file:///var/containers/Bundle/Application/16B00380-9909-4D99-B4CA-B02DA895431B/Pilot%20Forge.app/www/templates/Menu.html。 仅 HTTP 支持跨源请求

<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
  </head>
  <body>
    <script type="text/javascript">
        var Appclaim = angular.module("app_forge", []);
        Appclaim.controller("claimController", function ($scope) {                
            $scope.MenuTemplate = {
                Name: "Menu.html",
                Url: "templates/Menu.html"
            }
        });
    </script>
    <form name="form" ng-app="app_forge" ng-controller="claimController">
        <div>{{MenuTemplate.Name}}</div>
        <div ng-include="MenuTemplate.Url"></div>
    </form>
  </body>
</html>

【问题讨论】:

  • 您有两个表单打开标签和一个无表单关闭标签。这可能是一个错字。
  • 只需将 url 更改为 localhost 而不是 localhost。如果您从本地打开 html 文件,您应该创建一个本地服务器来提供该 html 文件

标签: ios angularjs phonegap


【解决方案1】:

今天刚刚遇到这个问题 - 将此添加到 ios 平台部分下的 config.xml 中已为我解决了这个问题。

<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />

确保您添加了最新版本的 iOS 平台/并且您使用的是 WKWebView 而不是 UIWebView。

这是一个帮助找到答案的 GitHub 问题:

Cordova not allowing https cross origin requests.

这里是 Cordova 网站上文章的链接:

UPDATED: How to handle the 'Deprecated API Usage - UIWebView' warning while uploading to the App Store

我猜 iOS 现在将所有 file:// 协议都视为跨源协议。 (事实证明,开发 iOS 是一件很痛苦的事情。)

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 2015-02-20
    • 1970-01-01
    • 2017-02-07
    • 2016-11-24
    • 2018-03-27
    • 2014-12-07
    • 1970-01-01
    相关资源
    最近更新 更多