Using three.js in Angular2

I am trying to integrate a three.js scene into an angular 2 page. I am new to angular 2 and javascript, I have included the three.js file in the script tag, in index.html, that is, and in the scene.component.ts file I have one the code...

//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 displayed on the line - import {THREE} of "three-js / three";

This is in the same directory path as 'angular2 / core'

Thanks in advance.

+4
source share
4 answers

do you use angular cli?

if so, be sure to add the link to the 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();
+4
source

ng2-three-demo, Angular ThreeJS.

, .

+3

, :

import * as THREE from 'three';
+2

Angular 2 , , system.js.

Angular 2 + three.js .

, .

!

+1

Source: https://habr.com/ru/post/1657982/


All Articles