Office.js getFilePropertiesAsync fails on second call in Angular.js

509 views Asked by At

I have an Office Task Pane App written with Office Javascript API (Office.js) that calls Office.context.document.getFilePropertiesAsync and places the returned URL in an angular variable:

$scope.getDocumentUrl = function () {

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

I then have a button that calls this. This works file the first time, but when I press the button a second time, it never enters the callback and displays this error:

TypeError: Object expected at verifyAndExtractCall (https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js:11:54588) at Anonymous function (https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js:11:83048) at Anonymous function (https://localhost:44304/scripts/office/1.1/o15apptofilemappingtable.js:11:86071) at $scope.getDocumentUrl (https://localhost:44304/AngularJs/controllers/sandpit.controller.js:130:6) at $parseFunctionCall (https://localhost:44304/AngularJs/bower_components/angular/angular.js:12403:7) at callback (https://localhost:44304/AngularJs/bower_components/angular/angular.js:21566:17) at Scope.prototype.$eval (https://localhost:44304/AngularJs/bower_components/angular/angular.js:14466:9) at Scope.prototype.$apply (https://localhost:44304/AngularJs/bower_components/angular/angular.js:14565:11) at Anonymous function (https://localhost:44304/AngularJs/bower_components/angular/angular.js:21571:17) at jQuery.event.dispatch (https://localhos

This is a simplified version of another situation that creates the same error. It also happens with getFileAsync. I know I need $scope.$apply to display the change. I know you can get the URL in other ways. I need to know the cause of the error.

1

There are 1 answers

1
Kejing Peng On

I test your scenario in my local machine. I could not repro your issue.

My simple test app has two files: AngularTest.html and AngularTest.js.

Content in 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>

Content in 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) {      
    };
})();

You can obtain the URL by clicking the button "Get Url". I tested it in Excel 2013 SP 1.