我使用npm install waypoints安装了Waypoints库,并使用
添加了类型 npm install --save @types/waypoints
。
我收到错误/node_modules/@types/waypoints/index.d.ts'不是模块。
Using waypoints.js in Angular 4 application
讨论了相同的问题。用户有相同的错误。 有一条评论建议“使用export package_name = package_name。这应该可行”,我不知道如何实现。
我尝试添加
export = waypoints
export as namespace waypoints;
declare namespace waypoints {
}
import * as Waypoint from 'waypoints';
当我尝试导入航路点时,没有任何错误。 但是,如果我再添加一个这样的航点:
let waypoint = new Waypoint.Waypoint({
element: document.querySelector("#p5"),
handler: function () {
},
});
我遇到另一个错误->
未找到模块:错误:无法解析“航路点”
答案 0 :(得分:0)
出口
export = waypoints
export as namespace waypoints;
declare namespace waypoints {
}
不能解决问题。不要更改@ types / waypoints中的任何内容,只需将declare const Waypoint: any;
添加到需要的组件中即可。就像简单的例子一样
declare const Waypoint: any; // Declare the Waypoint class here to access it
@Component({
selector: 'my-comp',
template: '<div id="abc">Abc</div>',
})
export class MyComponent implements OnInit {
ngOnInit() {
let wp = new Waypoint({
element: document.getElementById("abc"),
handler: (direction) => {
if (direction == 'down') {
wp.element.classList.add("fadeInUp");
wp.destroy();
}
},
offset: '95%'
});
}
}
这是解决组合错误的方法。我们知道一旦应用运行,Waypoint
就会出现,因此只需声明类型为Waypoint
的{{1}}类就可以解决问题。