在Angular2中使用three.js

前端之家收集整理的这篇文章主要介绍了在Angular2中使用three.js前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图将three.js场景集成到一个有角度的2页.我是Angular 2和 javascript的初学者,我在script.html中包含了脚本标签中的three.js文件,即在scene.component.ts文件中我有这样的代码

//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();
}
///////////////

问题在于显示 – 从’three-js / three’导入{THREE};

它与’angular2 / core’位于相同的目录路径中

提前致谢.

解决方法

你使用角度cli?

如果是这样,请不要忘记在typings.d文件添加引用:

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();

猜你在找的Angularjs相关文章