Search code examples
jqueryangularfroalaangular5

Property 'FroalaEditor' does not exist on type 'JQueryStatic' - Angular 4


I am using Angular 4 'FroalaEditor' which uses 'JQuery'.

I have implemented it successfully. Now I need to add custom buttons in that plugin.

I found following solution

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import * as $ from 'jquery';

@Component({
  selector: 'app-froala-editor',
  templateUrl: './froala-editor.component.html',
  styleUrls: ['./froala-editor.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class FroalaEditorComponent implements OnInit {
  options;
  constructor() { }

  ngOnInit(){
    $.FroalaEditor.DefineIcon('alert', {NAME: 'info'});
    $.FroalaEditor.RegisterCommand('alert', {
      title: 'Hello',
      focus: false,
      undo: false,
      refreshAfterCallback: false,
      callback: function () {
        alert('Hello!');
      }
    });

    this.options={
      toolbarButtons: ['bold', 'italic', 'underline', 'paragraphFormat','alert', '|', 'insertLink', 'insertImage', 'specialCharacters', 'color', '|', 'align', 'formatOL', 'formatUL', '|', 'undo', 'redo', 'clearFormatting', 'print'],
    }
  }

}

But I am having following error.

Property 'FroalaEditor' does not exist on type 'JQueryStatic'.

I found this solution, but I'm not sure how to implement it.

Have anyone faced this issue?


Solution

  • The solution that worked for me was to add declare var $: any; instead of import * as $ from 'jquery'; right after the imports in the component using the Editor.