Combining MxGraph with AngularJS 1 for Seamless Integration

I recently attempted to dynamically add mxgraph with the client-side library angularjs, but I couldn't find any relevant documentation on how to do so. Can anyone offer guidance on integrating mxgraph, such as which files need to be included and what needs to be called from the HTML file to make it functional?

app.js var app = angular.module('app', ['mxGraph']);

mxcontroller.js:

app.controller('Ctrl', ['$scope', 'mxgraph',
 function($scope, mxgraph) {
          $scope.main = function(container)
     {

             var graph = new mxgraph(container);
             var parent = graph.getDefaultParent();
             graph.getModel().beginUpdate();
             try
             {
                 var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
                 var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
             }
            finally
             {
                 graph.getModel().endUpdate();
             }
     }; }]);

index.html has been updated to include the mxgraph javascript/src folders.

mx.html

<div ng-controller="Ctrl as controller" id="content-container">

Thank you in advance for any assistance provided.

Answer №1

In order to integrate mxGraph into your AngularJS application, you will need to utilize AngularJS dependency injection if you are not already using an AngularJS factory, service, or provider for mxGraph.

One way to do this is by setting up a factory for mxGraph within your AngularJS module:

let mxgraphModule = angular.module('mxGraph', []);
mxgraphModule.factory("mxgraph", function() {
    return window.mxGraph; 
});

Afterwards, you can inject it into your controller like this:

app.controller('yourController', ['$scope', 'mxgraph', function($scope, mxgraph) { ... }]);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to utilize $save as $add in Firebase with Angular Fire?

Is it possible to utilize $save instead of $add in Firebase object for adding data? ...

Attempting to switch between classes with the click of a button

I am attempting to create a basic animation that involves changing an image from A to B to C when a button is clicked. However, I am encountering an issue with the error message Cannot read properties of undefined (reading 'classList'). I am puzz ...

Trying out a React component that relies on parameters for connection

Having an issue while attempting to test a connected react component that requires a props.params.id in order to call action creators. During the testing process, when checking if the component is connected to the store, an error "Uncaught TypeError: Canno ...

Implementing a permanent class following an incident

Is it possible to dynamically add a class to an element when an event occurs rather than based on a condition? For example, I have a td that displays a variable. <td>{{myVar}}</td>//myVar=10 When the variable changes to myVar=15, I want to ad ...

Creating Bubble Charts using npm highcharts with error code #17

I am attempting to create a bubble chart using Highcharts with the npm version, but I keep encountering error #17. I have tried importing highcharts-more without success... Here are my imports: import $ from "jquery"; import _ from "underscore"; import L ...

The return value from vue-query is ObjectRefImpl, not the actual data

Greetings to the Vue.js community! As a newcomer to Vue.js, I am seeking guidance on fetching data using vue-query, Vue.js 3, and the composition API. The data returned to me is ObjectRefImpl, but when I try to print the values, I encounter the error: "Pro ...

How to manually close the modal in Next.js using bootstrap 5

Incorporating Bootstrap 5.2 modals into my Next.js application has been smooth sailing so far. However, I've encountered an issue with closing the modal window after a successful backend request. To trigger the modal, I use the data-bs-toggle="modal" ...

Order sorting of comments in bootstrap-angular.js

I'm struggling to figure out how to display comments in a specific order by date, author, and rating in the input section. I also want them to be sortable in descending order if -date is typed. Check out this link for more information on comments sor ...

Removing values in javascript for checkboxes that are not selected

Here is the JavaScript Code : var clinicalStat; var id; var val; var clinicalVals; $(":checkbox").click(function() { //alert(" you checked"); if ($(this).is(':checked')) { var checked1 = $(this).val(); //Inital value of check ...

Deactivate the AJAX button after the specified number of clicks

Imagine I have a model called Post, and it can be associated with up to n Comments (where the number is determined by the backend). Now, let's say I have a view that allows users to add a Comment through an AJAX request. What would be the most effecti ...

Newbie React Developer Struggling to Implement Material-UI Example in React Project, State Functioning Differently from Hooks

I am currently in the early stages of learning React and trying to create a form for a project management web application. For this, I am using material-ui library. I referred to one of the select box component examples from the material-ui documentation ...

Is it possible to substitute an Angular component with a component from a custom module in a similar fashion to utilizing a decorator in AngularJS?

I am currently working on an application that caters to a diverse customer base. Each customer has unique customization needs for their user interface. We are interested in replacing certain components with customer-specific ones, but have been facing chal ...

Setting up JSL or JSlint with Node/Npm on an Ubuntu system

Seeking guidance on installing jsl-0.3.0 on Ubuntu 11.10. After downloading the tarball from JSL, I encountered issues due to the absence of a configure script or autogen.sh for building it from source. My attempt to use npm for installation failed as we ...

Efficiently process and handle the responses from Promise.all for every API call, then save the retrieved data

Currently, I am passing three API calls to Promise.all. Each API call requires a separate error handler and data storage in its own corresponding object. If I pass test4 to Promise.all, how can I automatically generate its own error and store the data in ...

deck.gl TripLayer showcases individual route mapping

I am interested in using Deck.gl to visualize trip data. I have successfully tested running local data with the example dataset provided, but when I tried switching to my own coordinates, I encountered issues and did not see any results. Does anyone have ...

AJAX Image Upload: How to Transfer File Name to Server?

Has anyone successfully uploaded an image to a web server using AJAX, but struggled with passing the file name and path to the PHP script on the server side? Here is the HTML code along with the JavaScript (ImageUpload01.php) that triggers the PHP: Pleas ...

Click on the input to pass the direct path of the image source

Here is the code snippet I'm working with: <script> function changeValue(o){ document.getElementsByName('NAME')[0].value=o; } </script> <span onclick="changeValue(this.innerHTML)" style="cursor: pointer;">One</ ...

Issue arises with variable not defined upon submission of ng-change event

Currently, I am attempting to save a variable from the date type input in HTML using AngularJS. In previous instances within this application, I was able to accomplish this with select tags instead of input tags and everything worked perfectly, confirming ...

Trouble with retrieving JSON data?

Struggling to access the JSON object issue: Received JSON Object: {"71":"Heart XXX","76":"No Heart YYYY"} I attempted to retrieve values for 71 and 72 individually but encountered compile time problems as: Syntax error on token ".71", delete this token ...

Customize the antd theme in a create-react-app project without the need to eject webpack

Struggling with customizing antd in my react app. I'm hesitant to mess with the webpack config.js file since I'm not well-versed in webpack. My goal is to avoid having a site that looks like a generic antd clone, but all my attempts at customizat ...