question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 2+ Integration

See original GitHub issue

Hi json-editor team, I have an angular 5 project and I can`t figure out how to properly import the json-editor module into an angular component.

So far I installed the jso-editor with npm and the status is like this.

angular ts

import { Component, OnInit } from '@angular/core';
import * as JSONEditor from '@json-editor/json-editor';
@Component({
  selector: 'app-angular-component',
  template: `<div id="configuration_editor"></div>`,
})
export class AngularComponent implements OnInit {
  configuration_editor: any;
  constructor() {
    const element = document.getElementById('configuration_editor');
    this.configuration_editor = new JSONEditor(element, {});
  }

  ngOnInit() {}
}

console output

Try `npm install @types/@json-editor/json-editor` if it exists or add a new declaration (.d.ts) file containing `declare module '@json-editor/json-editor';`

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
osharavcommented, Aug 7, 2018

To continue @trsh’s good advice, here is a full example:

import {Component, OnInit} from '@angular/core';
import * as JSONEditor from '@json-editor/json-editor';
import {Inject} from '@angular/core';
import {DOCUMENT} from '@angular/common';

JSONEditor.__proto__.constructor();

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  private doc: any;

  constructor(@Inject(DOCUMENT) document) {
    this.doc = document;
  }

  schema = {
    'type': 'object',
    'properties': {
      'aaa': {
        'type': 'string'
      },
      'zzz': {
        'type': 'integer'
      }
    },
    'required': [
      'aaa',
      'zzz'
    ],
    'additionalProperties': false
  };

  ngOnInit() {
    const elem = this.doc.getElementById('editor');
    const generatedUI = new (<any>window).JSONEditor(elem, {schema: this.schema});
  }

}

3reactions
belvederefcommented, May 6, 2020

I was able to make it work importing the package with:

import { JSONEditor } from '@json-editor/json-editor/dist/jsoneditor.js'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces ......
Read more >
Implement a single-page application with Angular 2
This tutorial introduces you to the key building blocks of Angular 2 and walks you through coding and running a SPA using Angular...
Read more >
Testing Angular 2 and Continuous Integration with Jest
Cut down on test run time by testing Angular 2 and continuous integration with Jest. In this article, using a toy application you'll...
Read more >
Angular Integration - Webix
The Webix library is compatible with the Angular (Angular 2+) framework. The integration with earlier versions is below. You can find an example...
Read more >
React vs. Angular 2 Integration with Rails - Pluralsight
In this guide, we will compare the React and the Angular 2 integrations using Ruby on Rails. The two approaches will be analyzed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found