0

I have developing an Excel add-in by mean-stack. Long time ago, I saw an answer somewhere about starting up an AngularJS add-in with office.js (unfortunately I cannot find the thread anymore). The following solution was suggested, though I don't remember what the initial problem was:

Office.initialize = function (reason) {
    jQuery(document).ready(function () {
        angular.bootstrap(document, ['app'])
    })
}

Now, I try to write <html ng-app="app"> and NOT use the above block (that allows me to lazy-load office.js). So far, it seems the add-in works as well.

So does anyone know if the <html ng-app="app"> way has any potential risk for an Excel add-in? Office.initialize is not mandatory, right?

Edit 1: I just realized that it did not work well in all the cases, here is the problem: Starting up an Excel add-in with ocLazyLoad failed in Excel for Windows.

SoftTimur
  • 5,630
  • 38
  • 140
  • 292

1 Answers1

1

Office.initialize is mandatory. The way that I've solved that problem was something like this.

Using $routeProvider configure your mapping of load controller to partial template loading.html.

$routeProvider.when('/',
{
    templateUrl: 'views/loading.html',
    controller: LoadController
}).when('/app',
{
    templateUrl: 'views/app.html',
    controller: AppController
});;

The block so far ensures when you're on the default start of the add-in with yourserver.org#/ url you're showing the load controller. In the html of your load controller, just put a spinner. So when your app loads, but office.js is not initialized yet, you're showing the spinner.

Now in your LoadControlleryou will initialize office.js and redirect to another partial view.

function LoadController(/* Your dependencies */){
    Office.initialize = function() {
         window.location.hash = 'app';
    }
}

in the LoadController where the '/' url of the angular app is showing just the loader. So the first template that you see is the loading template - but you're already in the angular app. When office.js initializes, it just points you to the actual experience.

Mavi Domates
  • 4,262
  • 2
  • 26
  • 45