尝试使用这个 html 模板创建一个 angular(11) 应用程序。https://bootstrapmade.com/flexstart-bootstrap-startup-template/
但是在模板的 js 文件中出现此错误。
main.js:29 Uncaught TypeError: Cannot read property 'addEventListener' of null
at on (main.js:29)
at main.js:113
at main.js:317
index.html,与模板 index.html 相同
<!-- Vendor CSS Files -->
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="assets/vendor/aos/aos.css" rel="stylesheet">
<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
<link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="assets/css/style.css" rel="stylesheet">
和 js,在angular.json
"scripts": [
"src/assets/vendor/bootstrap/js/bootstrap.bundle.js",
"src/assets/vendor/aos/aos.js",
"src/assets/vendor/php-email-form/validate.js",
"src/assets/vendor/swiper/swiper-bundle.min.js/",
"src/assets/vendor/purecounter/purecounter.js",
"src/assets/vendor/isotope-layout/isotope.pkgd.min.js",
"src/assets/vendor/glightbox/js/glightbox.min.js",
"src/assets/js/main.js"
]
和main.js
代码
[![(function() {
"use strict";
/**
* Easy selector helper function
*/
const select = (el, all = false) => {
el = el.trim()
if (all) {
return \[...document.querySelectorAll(el)\]
} else {
return document.querySelector(el)
}
}
/**
* Easy event listener function
*/
const on = (type, el, listener, all = false) => {
if (all) {
select(el, all).forEach(e => e.addEventListener(type, listener))
} else {
select(el, all).addEventListener(type, listener)
}
}]