0

我有一个用 Office Javascript API (Office.js) 编写的 Office 任务窗格应用程序,它调用 Office.context.document.getFilePropertiesAsync 并将返回的 URL 放在一个角度变量中:

$scope.getDocumentUrl = function () {

    Office.context.document.getFilePropertiesAsync(function (asyncResult) {
        $scope.url = asyncResult.value.url;
    });
};

然后我有一个调用它的按钮。这是第一次工作的文件,但是当我第二次按下按钮时,它永远不会进入回调并显示此错误:

TypeError:匿名函数(https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js :11:83048 ) 在匿名函数 ( https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js:11:86071 ) 在 $scope.getDocumentUrl ( https://localhost:44304/AngularJs/controllers/sandpit .controller.js:130:6 ) 在 $parseFunctionCall ( https://localhost:44304/AngularJs/bower_components/angular/angular.js:12403:7 ) 在回调 ( https://localhost:44304/AngularJs/bower_components/角/角.js:21566:17) 在 Scope.prototype.$eval ( https://localhost:44304/AngularJs/bower_components/angular/angular.js:14466:9 ) 在 Scope.prototype.$apply ( https://localhost:44304/AngularJs/bower_components /angular/angular.js:14565:11 ) 在匿名函数 ( https://localhost:44304/AngularJs/bower_components/angular/angular.js:21571:17 ) 在 jQuery.event.dispatch ( https://localhos

这是产生相同错误的另一种情况的简化版本。getFileAsync 也会发生这种情况。我知道我需要 $scope.$apply 来显示更改。我知道您可以通过其他方式获取 URL。我需要知道错误的原因。

4

1 回答 1

1

我在我的本地机器上测试你的场景。我无法重现您的问题。

我的简单测试应用程序有两个文件:AngularTest.html 和 AngularTest.js。

AngularTest.html 中的内容:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title></title>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js"></script>
    <script src="//ajax.microsoft.com/ajax/4.0/1/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" type="text/javascript"></script>
    <script src="AngularTest.js" type="text/javascript"></script>
</head>
<body>
    <div ng-app="myApp" ng-controller="myCtrl">
        <button ng-click="getDocumentUrl()">Get Url!</button>
        Url is: {{url}}
    </div>
</body>
</html>

AngularTest.js 中的内容:

(function () {
    "use strict";
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function($scope) {
            $scope.url = "";
            $scope.getDocumentUrl = function () {
                Office.context.document.getFilePropertiesAsync(function (asyncResult) {
                    $scope.url = asyncResult.value.url;
                });
            };        
        });        
    Office.initialize = function (reason) {      
    };
})();

您可以通过单击“获取 URL”按钮来获取 URL。我在 Excel 2013 SP 1 中对其进行了测试。

于 2015-06-17T21:48:03.637 回答