Utilizing Office.js: Incorporating Angular CLI to Call a Function in a Generated Function-File

After using angular-cli to create a new project, I integrated ng-office-ui-fabric and its dependencies. I included in index.html, added polyfills to angular.json, and everything seemed to be working smoothly.

When testing the add-in in Word, the taskpanes I created were loading and functioning as expected. However, there is a function-file in the manifest that allows a button on the ribbon to directly call a JavaScript function from the function-file.html. While I could include a JS and HTML file as assets in the project, I preferred to code in TypeScript rather than JavaScript. My attempt to define the functions within a component page of the project and reference it in the manifest as the functionfile did not yield the desired results.

So my inquiry is this: If office.js can call a JavaScript function from a separate HTML file, how can I achieve the same functionality with a routed Angular page containing TypeScript-written components? Do I need to export the function somewhere? Could the issue be related to late loading? Why isn't it working as expected? Would defining these functions in main.ts resolve the problem?

Answer №1

Opening the function-file.html from a ribbon button results in it launching in a separate instance of Internet Explorer, with its own JavaScript engine and session context. There is no sharing of session storage between the task pane and this separate instance. Communication between the two can only be achieved through Local Storage or common server-side data storage.

For Office add-ins using a single-page framework and featuring a custom ribbon button, there are two primary options:

(1) Opt for a hybrid approach by creating a dedicated page and function to serve as the launch target for the ribbon button. This serves as a separate app hosted within the same domain as the main single-page app, offering simplicity and ease of implementation.

(2) Alternatively, integrate the desired function into the main app and assign a route to it, using this route as the URL for the function in the app's manifest. However, it’s important to note that taking this route will result in loading a complete second instance of the single-page app within the IE instance launched by the ribbon button. The startup logic of the app must be carefully designed to prevent the standard starting view from loading when triggered by the special route.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing multiple server-side methods on an AJAX call in ASP.NET MVC: A comprehensive guide

I am facing a situation where I have a method that is called by jQuery, and its result is displayed on a popup. Sometimes, it takes some time to complete and a blank popup appears with processing message. When clicking on close, the popup disappears but th ...

How to ensure the table fits perfectly on the screen using JQueryMobile and Cordova?

I've been working on a JavaScript function that creates a dynamic page and displays data fetched from a database. However, I've encountered an issue where the displayed data overflows past the width of the mobile screen. Is there a way to ensure ...

Rerender not occurring after array splice with React hooks setter

My parent component structure is as follows: import React from "react"; import Test from "./Test"; function App() { const [configs, setConfigs] = React.useState([1, 2, 3]) return ( <div> ...

What is the best way to apply the TableRow style in material-ui / mui to make it similar to TableHead?

Trying to implement TableHead styling on TableRow but encountering a warning: validateDOMNesting(...) cannot be a child of. How can this be fixed without triggering a warning message? CollapisbleTableRow.js import React, { Fragment, useCallback } from &ap ...

"Utilizing ng2 dragula allows for the seamless addition of new data to an element after it has been dropped, based on the

My experience with the ng2 Dragula library revealed some intriguing aspects. I noticed that when dragging an element from one container to another, the element would expand to showcase additional data features such as Droplists, HTML input forms, and more ...

Is the 'match()' method available in node.js? If it is, what is the proper syntax to use it?

I attempted to utilize the .match() method in node.js, but encountered an error stating that has no method 'match'. Here is the section of code where I invoke the method: fs.readFile('proxy.txt', function (err, data) { if (data.mat ...

When transferring files to the src/pages directory in Next.js, the custom _app and _document components are not recognized

The documentation for Next.js mentions that the src/pages directory can be used as an alternative to /pages. However, I encountered a problem when moving my custom _app.tsx and _document.tsx files into the src folder, as they were being ignored. If you cr ...

A guide on updating table rows in Material UI and React Table

I am currently developing a table using Material UI/React that consists of multiple text fields per row and permits users to delete specific rows. Each row in the table is generated from a list, and I am utilizing React's state hooks to manage the sta ...

What steps should I take if the slackbot is properly functioning after being invited to the channel?

Using an OAuth2 token I am looking to automate the process of sending data from Google Sheets via Slackbot. Even though I have set up tokens and connections, I find that I still need to manually input the channel id into my script. In order to streamline ...

Don't allow users to switch views without saving their changes

We are working with a Backbone.js application that presents various forms to users. Our goal is simple: if a user navigates away from the page without saving the completed form, we need to show a confirmation dialog. When dealing with traditional forms, i ...

Managing a large number of records in a for loop on a Node.js server can be challenging, especially when dealing with nearly

After setting up a NodeJS server and connecting it to a MySQL database with around 5000 users, I needed to read the data from MySQL and update a MongoDB database. I managed to write code for this process. https://gist.github.com/chanakaDe/aa9d6a511070c3c78 ...

What is the best way to eliminate mouse click release events?

Encountering an issue with my Vue/Vuetify Dialog that closes when clicking outside of it as expected. The problem arises when there is a text field inside the dialog. If I accidentally select the content and release the mouse outside of the dialog, it als ...

Making Angular2 Templates More Efficient with Array.prototype.filter()

I have a variable named networkInterface that includes an array called services. My objective is to create a checkbox input that indicates whether a specific service_id exists within the services array of the networkInterface. An illustration of JSON `int ...

What is the best way to implement nested iterations in Jade?

ul li a(href='') menu1 li a(href='') menu2 ul li a(href='') sub-menu2 li a(href='') menu3 ul li a(href=&apos ...

What is the proper way to end a WebSocket connection?

Can a websocket connection be terminated by the server without closing the entire server? If so, how can this be done? Note: My back-end is implemented using NodeJS and I am using the 'ws' websocket module. ...

How to create a responsive image that appears over a button when hovering in Bootstrap?

My goal is to display an image over a button when hovering. I've tried adding the .img-responsive class in Bootstrap while including the image in the HTML, but it's not working as expected with my current method of loading images. The buttons the ...

Is there a way to iterate through objects and add new properties to them?

I am trying to achieve the following object: let newPost = { title: "Post 1", Content: "New content" } with the code below: let newPost = {}; let postData = $(".post-data").each (function(index) { newPost.title = $ ...

When you click on the text, the calendar will pop up for you to

When the text "SetExpiryDate" is clicked, a date picker opens. After selecting a date, the text changes to "Expires ${date}" where the selected date is inserted. If no date is selected, the text remains as it is. I'm curious how I can implement this ...

Ways to create two separate references pointing to a single object

Here is the code I am currently running: function TypeOfCar(vehicle) { this.vehicle = vehicle; } var sedan = new TypeOfCar('sedan'); var carType = race; console.log(carType); console.log(sedan); After running the code, the output is as follo ...

Utilizing Angular 2 for Displaying SVG Information

I am facing an issue with my angular application where I need to display product information in a SVG image obtained from a service in JSON format. Despite trying different methods, I have been unsuccessful in rendering the image on the HTML template. Att ...