【发布时间】:2018-03-19 07:21:35
【问题描述】:
我开始在angular.io中使用three.js,出现这个错误:
(index):18 Error: (SystemJS) THREE is not defined
ReferenceError: THREE is not defined
at Object.eval (http://localhost:3000/node_modules/three/examples/js/controls/OrbitControls.js:16:1)
at eval (http://localhost:3000/node_modules/three/examples/js/controls/OrbitControls.js:1044:4)
at eval (http://localhost:3000/node_modules/three/examples/js/controls/OrbitControls.js:1045:3)
at eval (<anonymous>)
Evaluating http://localhost:3000/node_modules/three/examples/js/controls/OrbitControls.js
Evaluating http://localhost:3000/app/three-basis/three-camera-orbit-control.component.js
我的导入和组件:
import {Component} from '@angular/core';
import {CameraProvider} from './camera-provider.service';
import 'threejs/controls/OrbitControls';
import {OrbitControls} from 'three';
@Component({selector: 'three-camera-orbit-control', template: ''})
export class ThreeCameraOrbitControlComponent {
constructor(private cameraProvider: CameraProvider) {
let camera = this.cameraProvider.getCamera();
let controls = new OrbitControls(camera);
controls.addEventListener('change', () => {});
}
}
如果我在我的 node_modules/three 中的 OrbitControls.js 中添加此 var THREE = require("three");,则错误消失并且一切正常。我还不太擅长js,请有人帮助我,如何正确地做到这一点?谢谢。
【问题讨论】:
-
有添加新模块三轨道控制-ts的解决方法,不喜欢这样,想了解js/angular级别的问题。
标签: javascript angular typescript three.js