我正在使用 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/