在 Angular2 中使用three.js [英] Using three.js in Angular2
问题描述
我正在尝试将一个three.js 场景集成到一个角度为2 的页面中.我是 Angular 2 和 javascript 的初学者,我在 script 标签中包含了three.js文件,在index.html中,即,在scene.component.ts文件中我有这样的代码......>
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();
}
///////////////
问题显示在行中 - import { THREE } from 'three-js/three';
The problem is showing in the line - import { THREE } from 'three-js/three';
这与'angular2/core'在同一目录路径
This is in the same directory path as 'angular2/core'
提前致谢.
推荐答案
你在使用 angular cli 吗?
are you using angular cli?
如果是这样,请不要忘记在typings.d 文件中添加引用:
if so, don't forget to add the reference in your typings.d file:
declare module 'three';
https://github.com/angular/angular-cli#第 3 方库安装
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();
这篇关于在 Angular2 中使用three.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!