I am trying to integrate a three.js scene into a angular 2 page. I am a beginner in Angular 2 and javascript, I have included the three.js file in the script tag, in index.html, i.e, and in the scene.component.ts file I have the code like this...
//scene.component.ts
import { Component } from 'angular2/core';
import { THREE } from 'three-js/three';
@Component({
selector: 'ps-scene',
templateUrl: 'app/webgl/scene.component.html'
})
export class SceneComponent{
scene = new THREE.Scene();
}
///////////////
The problem is showing in the line - import { THREE } from 'three-js/three';
This is in the same directory path as 'angular2/core'
Thanks in advance.
are you using angular cli?
if so, don't forget to add the reference in your typings.d file:
declare module 'three';
https://github.com/angular/angular-cli#3rd-party-library-installation
3rd Party Library Installation
Simply install your library via npm install lib-name --save and import it in your code.
If the library does not include typings, you can install them using npm:
npm install d3 --save
npm install @types/d3 --save-dev
If the library doesn't have typings available at @types/, you can still use it by manually adding typings for it:
// in src/typings.d.ts
declare module 'typeless-package';
// in src/app/app.component.ts
import * as typelessPackage from 'typeless-package';
typelessPackage.method();
Checkout this ng2-three-demo, where I use Angular Components to define objects for ThreeJS.
Additionally, there is a presentation on the topic itself in the repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With