Free Support Forum -

GroupDocs Viewer and AngularJS


Hello, GroupDocs team.
You know how popular AngularJS today. However, couldn’t find any valuable sample of how to make it work within AngularJS, RequireJS etc. without lots of pain.

So here are some details and questions.
It’s clear that back-end should be implemented let’s say using .NET 4.0. GroupDocs samples for .NET show the approach, when it’s needed to make a couple of requests to make viewer work:
1. GetJavaScriptLibraries - to retrieve script links to dependencies for viewer. + It returns a couple of script tags with data that looks important (applicationPath, useHtppHandlers etc.). This also depends on what is called on server side for viewer data generation.
2. GetInlineDocumentScript - to retrieve viewer script itself and depends on what is called on server side for its generation.

At first glance calling such 2 methods is OK. However, it does not work well when we talk about AngularJS with RequireJS.

Regarding to this, I assume that all the data returned by that server methods can be injected via requireJS without calling web service and scripts can be stored inside client app.
However, it would be great if pointed below assumptions are correct:
1. Libraries can be injected and loaded without calling ‘GetJavaScriptLibaries’ from server. They can be loaded directly via RequreJS on client side.
2. Service variables like ‘applicationPath’ and ‘useHttpHandlers’ can also be set on client side manually without calling pointed method.
3. InlineDocumentScript - this also looks like a data that can be stored on client and can be injected via requireJS directly without calling web service.
The biggest cons of such approach is that service updates should be in sync with SPA all the time. Changing service - will require manual update of client app JS. However, this is something that our team can deal with.
Is there anything else what we cannot see?
Or maybe you can propose a better approach to fit pointed stack?




Thank you fro your interest in GroupDocs. The method Viewer.CreateScriptLoadBlock() returns not only public libraries, it’s also return a specific Viewer scripts and styles. You can run it once, check what libraries are returned and save them as a JavaScript files for manual including.

As for InlineDocumentScript - yes, you can do same for it. Just run it once (in a common way) check the JavaScript which will be generated and save it as a JavaScript file.

For example how to run GroupDocs.Viewer with AngularJs you can download our sample here and get all JavaScript you need from it.

Thank you.


Thanks for you reply, Pavel.
This 100% matches to what I’ve described in my question. So that’s good that we’re on the correct track.