gpt4 book ai didi

javascript - 如何调用 Angular 组件中 asset 文件夹下单独文件中的外部 Javascript 函数?

转载 作者:行者123 更新时间:2023-12-01 02:36:50 25 4
gpt4 key购买 nike

enter image description here

enter image description here

//Way 1 - Not working
import { LoadCarouselAndPopup } from '../../../assets/js/main.js';
LoadCarouselAndPopup();

//Way 2 - Not working
declare var System: any;
System.import('../../../assets/js/main.js')
.then(xJS => {
xJS.LoadCarouselAndPopup();
});

}

以上两种方法我都试过了。

在第一种方式中,我无法编译代码,因为它会抛出“错误 TS5055:无法写入文件'main.js',因为它会覆盖输入文件”之类的错误。在本例中,我还添加了“allowJs: true”。

在方式 2 中,我收到了“无法读取未定义的属性‘call’”之类的错误..

帮我解决这个问题。提前致谢。

最佳答案

正如我所看到的图像中的文件夹结构,我相信您正在使用 angular-cli 来实现此目的,因此您可以通过在 .angular-cli.json 中包含该脚本的路径来包含外部脚本 脚本数组中的文件

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "dummy-project"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": ['assets/filename.js],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}

关于javascript - 如何调用 Angular 组件中 asset 文件夹下单独文件中的外部 Javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47846152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com