Miro J.
Miro J.

Reputation: 4964

What is the best way to use Office ribbon commands with AngularJS app

I have an Office add-in, which is built with AngularJS (1.4) on top of ASP.NET MVC 4.5. I have a lot of functionality already implemented in Angular controller and service JS files.

Recently, I started experimenting with the Office ribbon buttons and commands (JS API 1.3). I want to access JavaScript functions in my Angular files ($scope or service) from the ribbon buttons. What is the best way to do that?

Upvotes: 2

Views: 296

Answers (1)

Rick Kirkham
Rick Kirkham

Reputation: 9684

As you have probably discovered, the add-in commands (ribbon buttons, menu items) introduced with Office JS API 1.3 are designed so that each one launches its own execution context and has its own global (window) object. The execution context of the main add-in app in the task pane is not accessible directly from these other execution contexts.

One thing you might try is using local storage to pass information between the two contexts. There is an overview of how to do this Sharing data across windows using localStorage. Basically, your add-in command leaves a message in localStorage requesting an action. Your task pane app responds to the storage event, reads the message, and performs the requested action.

Upvotes: 2

Related Questions