簡體   English   中英

無法將腳本文件添加到組件html

[英]cant add script file to components html

我在index.html(root)中有一個腳本文件引用; index.html的:

    <script src="page1.js"></script>
<script src="assets/sliderfunctions.js"></script>
<script src="assets/js/custom.js"></script>

這里不需要sliderfunctions.js,它包含一些關於滑塊的特定功能,所以我把它帶到slider.component.html文件,但是你猜它不能正常工作,因為我實際上從未加載到瀏覽器..

slider.component.ts:

import {Component,ViewEncapsulation} from '@angular/core';

@Component({
    selector:'app-slider',
    templateUrl:'../templates/slider.component.html'
})
export class SliderComponent{
    constructor(){}
}

slider.component.html:

 <script src="page1.js"></script>
<script src="assets/sliderfunctions.js"></script>
<script src="assets/js/custom.js"></script>

(我帶了3個,因為腳本的順序很重要)所以我想得到一個特定的點,我已經在網上搜索但是無法弄清楚如何在組件模板中添加腳本文件

您正在考慮的方式被視為安全威脅。 你可以按照這個答案

要么

您可以通過執行System.import / require來引用component.ts文件中的腳本文件

System.import('filepath.js'); //or below one
require('filepath.js');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM