0

Office.context.document.getFilePropertiesAsync を呼び出し、返された URL を angular 変数に配置する Office Javascript API (Office.js) で記述された Office タスク ペイン アプリがあります。

$scope.getDocumentUrl = function () {

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

次に、これを呼び出すボタンがあります。これは最初は機能しますが、ボタンを2回押すと、コールバックに入らず、次のエラーが表示されます。

TypeError:匿名関数 ( https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js ) の verifyAndExtractCall ( https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js:11:54588 ) でオブジェクトが予期されます: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 の 2 つのファイルがあります。

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 に答える