14

应用程序运行但 Angular 数据对象无法识别。

这是我得到的 JavaScript 错误:

Exception was thrown at line 1059, column 11 in ms-appx://28934b41-4dd2-4414-b9a9-
a73c11c1b743/js/angular.js
0x800a139e - JavaScript runtime error: No module: ngLocale
Exception was thrown at line 4473, column 9 in ms-appx://28934b41-4dd2-4414-b9a9-
a73c11c1b743/js/angular.js
0x800a139e - JavaScript runtime error: HierarchyRequestError
The program '[5112] WWAHost.exe' has exited with code 1 (0x1).

这是 angular.js 中第 1059 行附近的函数:

return ensure(modules, name, function() {
    if (!requires) {
      throw Error('No module: ' + name);
    }

这是第 4473 行附近的函数:

 if (parent) {
    parent.replaceChild(newNode, oldNode);
  }

我能够修复遇到的第一个错误:

Unhandled exception at line 2031
 JavaScript runtime error: Unable to add dynamic content

通过包装所有 angular.jsMSApp.execUnsafeLocalFunction

  MSApp.execUnsafeLocalFunction(function () {
          ....
      });   

这些错误来自我按照 Angular.js 主页中的待办事项列表示例创建的测试应用程序。

怎么办?根据我参加的免费 Microsoft 活动,“将任何第三方 JavaScript 框架/库添加到 Windows 8 应用程序很容易!” 我可能对此很陌生……但我认为这并不容易!

甚至可以将 Angular.js 与 Windows 8 应用程序一起使用吗?

4

3 回答 3

23

原因是 Angular<!-- -->为 ng-repeat 和类似指令放置了 html 注释标签。不幸的是,微软认为这些在使用 .innertHTML 从 Javascript 中输入时是不安全的,并且是不允许的。这可以在这里找到:

http://msdn.microsoft.com/en-us/library/windows/apps/hh465388.aspx

它发生在 jQLite 的第 1534 行:

var div = document.createElement('div');
            // Read about the NoScope elements here:
            // http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx
            div.innerHTML = '<div>&#160;</div>' + element; // IE insanity to make NoScope elements work!
            div.removeChild(div.firstChild); // remove the superfluous div

发生的事情是元素是

<!-- ngRepeat: item in arrayTest -->

然后当 angular 执行 div.innerHTML = ... 时,元素被删除。如果在 div.removeChild 处设置断点,您会注意到 div.innerHTML 没有该元素。

[编辑] 写完这个回复后,我尝试添加

MSApp.execUnsafeLocalFunction(function () { div.innerHTML = '<div>&#160;</div>' + element });

有用!显然,您必须将所有 angularjs 包装在 MSApp.execUnsafeLocalFunction 中,然后专门包装该行。

于 2012-10-28T05:07:27.243 回答
4

I got it working by adding ng-csp to the HTML tag in my store app. This enables Content Security Policy, which disables things like 'eval'. I used the jQuery(v2.1.1) and the Angular(v1.3.0-beta.13).

More on ng-csp in the AngularJS documentation.

于 2014-06-24T22:09:55.630 回答
1

在我的情况下,我用 MSApp.execUnsafeLocalFunction 包装了angularjs,我只使用了 data-ng-repeat 而不是 ng-repeat

于 2013-12-12T16:45:31.640 回答