Help with Tago.io Custom Widget in Angular

Hi. I’m trying to use Angular to develop a custom widget for Tago.IO using VSCode and have a sample (non-Tago.IO) Angular app compiling & running OK. I also have the @tago-io/custom-widget node module installed in a simple Angular app, but I’ve been unable to get past the following issue: When I import “@tago-io/custom-widget” I always get the following error at runtime:

ReferenceError: window is not defined
at eval (/…/NgHello1/.angular/cache/20.2.1/NgHello1/vite/deps_ssr/@tago-io_custom-widget.js:333:5)
at eval (/…/NgHello1/.angular/cache/20.2.1/NgHello1/vite/deps_ssr/@tago-io_custom-widget.js:498:5)
at eval (/…/NgHello1/.angular/cache/20.2.1/NgHello1/vite/deps_ssr/@tago-io_custom-widget.js:499:3)
at async ESModulesEvaluator.runInlinedModule (file:///…/NgHello1/node_modules/vite/dist/node/module-runner.js:910:3)

How does one handle the global ‘window’ object for Tago.io custom widgets with Angular? Also, are there any good examples (or code skeletons) of how to write a custom widget for Tago.io in Angular available somewhere?

Thanks again for the community support!

With a lot more Google searching, I think I solved my issue here: The problem was my Angular app skeleton had server-side rendering (SSR) enabled so the browser’s global ‘window’ object was not available on the server side. I switched it to static output mode with client-side rendering (no SSR) and it seems to be starting to work now.

Hi @jd8086

I’m glad to hear you were able to solve the issue!
At the moment we don’t have examples of custom widgets in Angular — most of our docs and samples are in React. But if you make progress with Angular and feel like sharing, it could definitely help other developers too.

Thanks Gustavo. It may take me as while as this is just a “spare time” side project, but if I eventually succeed I hope to publish a usable Angular skeleton for custom Tago.io widgets and perhaps a generally useful custom widget or two based on the skeleton.

2 Likes