How to use verovio in Angular? #3562
-
I took a look at PianoPlay which is an Angular app that uses verovio so I guess this can be done. I wrote the following angular service which is inspired by this service. import { Injectable } from '@angular/core';
declare var verovio: any;
@Injectable({
providedIn: 'root'
})
export class DocumentService {
private vrvToolkit: any;
constructor() {
this.vrvToolkit = new verovio.toolkit();
console.log(this.vrvToolkit);
}
} But when this code runs I get I have installed verovio using
How can I make verovio work with Angular? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I am not sure if this can help, but @WolfgangDrescher put together some helpful examples for other frameworks. Maybe you can find there information on how it could work? |
Beta Was this translation helpful? Give feedback.
-
With Angular you probably want the ESM Version of Verovio. Keep in mind, that full ESM support is currently not possible due to some limitations with Emscripten. But depending on your bundler you can get around this. Here is the link to my Vue.js implementation: https://github.com/WolfgangDrescher/vue-verovio-canvas Your code should look similar to this: import createVerovioModule from 'verovio/wasm';
import { VerovioToolkit } from 'verovio/esm';
createVerovioModule().then(VerovioModule => {
const toolkit = new VerovioToolkit(VerovioModule);
toolkit.loadData(...);
const svg = toolkit.renderToSVG();
}); If you use Vite as a bundler you will have to use: export default defineConfig({
optimizeDeps: {
exclude: ['verovio'],
},
}); Specifically on PianoPlay it looks like Verovio is added as a global variable (which is not the best solution in in my opinion): https://github.com/search?q=repo%3Adeanmalone%2FPianoPlay+verovio&type=code |
Beta Was this translation helpful? Give feedback.
With Angular you probably want the ESM Version of Verovio. Keep in mind, that full ESM support is currently not possible due to some limitations with Emscripten. But depending on your bundler you can get around this.
Here is the link to my Vue.js implementation: https://github.com/WolfgangDrescher/vue-verovio-canvas
Your code should look similar to this:
If you use Vite as a bundler you will have to use: