I have installed jointjs via npm and also installed typings and code compiles/builds fine.
Code
import { Component } from '@angular/core';
import * as joint from '../../node_modules/jointjs/dist/joint.min';
export class AppComponent {
title = 'app works!';
constructor(
) {
// console.log(joint)// private jint: joint,
}
ngOnInit() {
var graph = new joint.dia.Graph;
}
}
Error shows up on the browser:
Failed to compile.
/home/vinay/angularapps/jjs/src/app/app.component.ts (17,31): Property 'Graph' does not exist on type '{}'.)
my cli.json file.. added the scripts and styles for jointjs
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"version": "1.0.0-beta.32.3",
"name": "jjs"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"styles": [
"styles.css",
"../node_modules/jointjs/css/layout.css"
],
"scripts": ["../node_modules/jointjs/dist/joint.js"],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"files": "src/**/*.ts",
"project": "src/tsconfig.json"
},
{
"files": "e2e/**/*.ts",
"project": "e2e/tsconfig.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
my tsconfig.json file where i added allowJs to true
{
"compilerOptions": {
"baseUrl": "",
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],
"mapRoot": "./",
"module": "es2015",
"moduleResolution": "node",
"outDir": "../dist/out-tsc",
"sourceMap": true,
"allowJs": true,
"target": "es5",
"typeRoots": [
"../node_modules/@types"
]
}
}
I am not able to figure out how to create a simple hello world application provided on this link http://resources.jointjs.com/tutorial/hello-world
I'm using @angular/cli : 1.0.4 version and im going to sum everything you need to run JointJS without a problem.
Use these commands to install npm packages correctly and make sure the right versions are present. Types on devdependencies and the libraries on normal dependencies thats important.
This is my scripts in the angular-cli.json file:
This is my styles in the angular-cli.json file to work properly:
And the examples are same as above. Hope i could help. Happy Coding!
npm install jointjs --save
./node_modules/jointjs/dist/jointjs.js
./node_modules/jointjs/css/layout.css
ok i finally got to get jointjs working with @angular cli and below are the steps
in the command prompt within the angular project directory
Make sure in package.json the entries show up under dependencies and devDepencies for backbone, jquery, jointjs, lodash and make sure they are of the versions
jointjs 1.0.3, backbome = 1.3.3, jquery = 3.1.1, lodash = 3.10.1
in angular-cli.json file
in the styles property and scripts;[ ] property add the joint js details like below
in your component.html
in your component.ts
Just to mention there are a few things wrong or missing in the accepted answer:
includes in component.ts should be:
you should add the version on the npm install commands for jquery and backbone to ensure to use the suggestioned version as mentioned.
you also (additionaly) must add following 2 css files into angular-cli.json:
use $ in the code rather than jQuery:
hth some one,
PS: i tested it with angular 4.1 and angular-cli 1.0.3