v1 docs   See v2 ↗

Angular 2+

Setup

To use Anymod with Angular 2+, add the Anymod script tag before (above) your Angular script tags in your HTML. Then make Anymod available in your .ts file:

declare var Anymod: any;

Now you can add your mod and call Anymod.render() to render the mod(s):

@Component({
...
template: `<div id=anymod-mldrn></div>`,
})
class AnymodDemo {
...
ngOnInit() {
Anymod.render()
}
}

You can use Anymod.render() by itself or with a callback or promise. See the section on Anymod.render for more.

Example

The following example shows a mod being rendered in typescript with Anymod.render:

Rendering multiple mods

You can render multiple mods the same way as a single mod, and you only need to call Anymod.render() once:

@Component({
...
template: `
<div id=anymod-mldrn></div>
<div id=anymod-eoako></div>
<div id=anymod-klaln></div>
`,
})
class AnymodDemo {
...
ngOnInit() {
Anymod.render()
}
}

Re-rendering

You can call Anymod.render() as often as you’d like in your Angular code (or elsewhere). This method will not lead to an API call every time; if a mod has already been fetched once, Anymod.render() will use that data instead of making another API call.

See the section on Anymod.render for more.