我正在使用 Three.js 开发 Angular2。
这是我的 Angular cli 配置。
在package.json中:
"three": "^0.81.2",
"three-stl-loader": "^1.0.4",
在 angular.cli.json 中:
"../node_modules/three/build/three.min.js",
"../node_modules/three/examples/js/Detector.js",
"../node_modules/three/examples/js/controls/OrbitControls.js",
"../node_modules/three/examples/js/controls/TrackballControls.js",
"../node_modules/three/examples/js/loaders/STLLoader.js",
在组件文件中,我加载了 THREE 和 OrbitControls:
import * as THREE from 'three';
import PerspectiveCamera = THREE.PerspectiveCamera;
import OrbitControls = THREE.OrbitControls;
当应用程序运行时,控制台会显示以下消息:
'THREE.WebGLRenderer 81
three.js:41149 THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.
three.js:41158 THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.
'
很明显, Three.js 已加载,但为什么 OrbitControls 找不到?
最佳答案
我遇到了类似的问题。这是我的解决方法,运行以下命令:
npm install three-orbit-controls
编辑 import 语句下@Component 上方的 component.ts 文件:
const THREE = require('three');
const OrbitControls = require('three-orbit-controls')(THREE);
现在它将被称为 OrbitControls 而不是 THREE.OrbitControls
关于angular - 类型错误 : OrbitControls is not a constructor in angular2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41681542/