angularjs - Office.js 回调破坏了 Angular Controller

标签 angularjs powerpoint office-addins office-js

我正在使用 AngularJS 开发 PowerPoint-AddIn。为了获取用户语言,我使用 Office.context.displayLanguage ,它仅在 Office.initialize -Callback 中可用。我通过 Angular-Factory 获取语言字符串。当我将 Office.initialize -Callback 放入我的 Angular Controller 中时,它会破坏 Controller 功能,并且我的页面上的按钮将不再起作用。我做错了什么?

myApp.controller('angularHomeController', ['$scope', 'lang', function ($scope, lang) {
    $scope.lang = lang.getLocaleStrings("en-US");
    Office.initialize = function (reason) {
        $scope.lang = lang.getLocaleStrings(Office.context.displayLanguage);
    }
}]);

我默认将语言设置为英语,但我希望在初始化文档时更改它,并且我可以访问显示语言。我的应用程序工作正常,直到我将 Office.initialize -Callback 放入我的 Controller 中。我应该以某种方式注入(inject) Office-Object 吗?我没有收到任何错误消息。

最佳答案

我在评论中提到了类似的问题。 您只需声明 Office.initialize在你的<head>标记并引导您的 Angular 模块在其中:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js" type="text/javascript"></script>

    <!-- Add the following script -->
    <script type="text/javascript">
        Office.initialize = function (reason) {
            angular.bootstrap(document, ['myOfficeModule']);
        };
    </script>

    <script type="text/javascript" src="../../Scripts/Angular/angular.min.js"></script>
    <!-- Other scripts -->

</head>
<body>
    <ng-view></ng-view>
</body>
</html>

注意:不再需要 ng-app="myOfficeModule"当您手动引导时。

它对我有用,现在是 Office可以从我的服务访问对象。我希望它也适合你。

使用来源:http://www.chaosm.net/blog/2014/07/27/load-angularjs-after-office-initialized/

关于angularjs - Office.js 回调破坏了 Angular Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33100354/

相关文章:

javascript - 使用 Office 插件更改 MS Word 中的主菜单

javascript - AngularJS : pass data from controller to controller without factory, 服务或广播?

javascript - 事件处理函数不适用于 `this` 关键字

javascript - 在 AngularJS 中为 Promise 设置超时处理程序

html - 构建我的 AngularJS 应用程序

c# - PowerPoint 打开 "Record Slide Show"对话框并检测演示文稿是否有录音 c# 插件

vba - 如何对PowerPoint VBA中的超链接执行错误检查?

c# - 如何在 Visio 2013 加载项中添加自定义面板?

office365 - 在 Office 应用程序中 - 无法重新定义不可配置的属性 'context'“

powerpoint - 如何在powerpoint中的超链接后从另一张幻灯片返回主幻灯片