我没有在angular文件中获取office.context.document的问题。我正在做的是点击功能区按钮我重定向到一个html页面,其功能是用角度j编写的.html页面包含一个输入框按钮。单击按钮我正在调用一个函数,该函数有office.context.document.getfileasync但是它的错误是来了office.context.document.getfileasync undefined。
(function() {
'use strict';
var count = 0;
var INSERTION_TYPE_PLAIN_TEXT = "PLAIN_TEXT";
var INSERTION_TYPE_RICH_TEXT = "RICH_TEXT";
var INSERTION_TYPE_LIVE_WIT = "WIT_CONTENT";
var VAR_META_SEPERATOR = "::";
angular.module('wpoffice')
.directive('wittyWordCommandExec', function() {
return {
restrict: 'E',
templateUrl: 'witty-save-document-from-ribbon-pop-up.html',
bindToController: true,
controller: 'WordCommandController',
controllerAs: 'WordCommandCtrl'
};
})
.controller('WordCommandController', WordCommandController);
/** @ngInject */
function WordCommandController($scope, $q, ngNotify, $uibModal, witService, $timeout,$http,appData,attachmentService,officeWordService,userProfileService) {
console.log('WordVariableController init');
var vm = this;
vm.init = init;
vm.createWit = createWit;
$scope.WitName = "";
console.log(Office.context.document);
console.log($scope.WitName);
var fileurl = displayDocumentUrl();
console.log(fileurl+"hi");
if(fileurl){
var filename = fileurl.substr(fileurl.lastIndexOf('/')+1,fileurl.length);
}
function createWit()
{
console.log(Office.context);
console.log($scope.WitName);
console.log("test function executed");
console.log(appData);
userProfileService.getUserProfileData().then(function(response){
console.log(response.defaultFolderId);
//console.log(filename);
saveDocument(appData, witService,attachmentService,response.defaultFolderId,$q,filename).then(function(){
console.log("Document saved to witty parrot");
});
},function(error){
console.log(error);
});
}
function init()
{
console.log("test init fucntion");
}
// Get all of the content from a PowerPoint or Word document in 100-KB chunks of text.
function saveDocument(appData, witService,attachmentService,defaultFolderId,$q,filename,witname)
{
var deferred = $q.defer();
appData.isContentLoaded = false;
console.log("inside sendfile");
console.log(Office.context.document);
Office.context.document.getFileAsync("compressed",
{ sliceSize: 100000},
function (result) {
console.log(result);
if (result.status == Office.AsyncResultStatus.Succeeded) {
var myFile = result.value;
var sliceCount = myFile.sliceCount;
var slicesReceived = 0, gotAllSlices = true, docdataSlices = [];
console.log("File size:" + myFile.size + " #Slices: " + sliceCount);
getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived,appData, witService,attachmentService,defaultFolderId,$q,filename,witname).then(function(){
console.log('inside getSliceAsync');
deferred.resolve();
});
}
else {
deferred.resolve();
console.log(result.status);
}
});
return deferred.promise;
}

<div class="flex-rem layout-column pad-box-10" ng-controller="WordCommandController as WordCommandCtrl">
<div class="layout-column flex-rem witty-text-input-container">
<input autofocus type="text" ng-model="WitName" placeholder="Enter wit name" class="flex flex-rem">
</div>
<button ng-click="WordCommandCtrl.createWit()" class="ms-Button ms-Button--primary">
<span class="ms-Button-label">CREATE WIT</span>
</button>
</div>
&#13;