Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import JS library in Angular

Tags:

angular

I am trying to use an external library in an Angular project. This is from the docs of https://github.com/bramstein/fontfaceobserver

If you're using npm you can install Font Face Observer as a dependency:

$ npm install fontfaceobserver
You can then require fontfaceobserver as a CommonJS (Browserify) module:

var FontFaceObserver = require('fontfaceobserver');

var font = new FontFaceObserver('My Family');

font.load().then(function () {
  console.log('My Family has loaded');
});

Library is imported using a require, but angular doesn't like that keyword. Is there some standard way of importing a library?

like image 763
sanjihan Avatar asked Oct 26 '25 18:10

sanjihan


1 Answers

If its webpack you should just be able to import it using es6 imports. Just installed it and this works for me:

import FontFaceObserver from 'fontfaceobserver'

this.font = new FontFaceObserver('ariel');

this.font look like this:

this.font = {
family:"ariel",
stretch:"normal",
style:"normal",
weight:"normal"
}
like image 83
rtn Avatar answered Oct 29 '25 08:10

rtn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!