2017-07-18 16 views
0

在component.ts那裏有一個列表,其中您聯繫網址是一個styleUrl對組件:可能將<script>添加到AngularComponent中?

okkook 

@Component({ 

    selector: 'home', 

    templateUrl: './home.component.html', 

    styleUrls: ['./home.component.css'] 

}) 

我怎麼能與我已經做了一個JavaScript文件? 我如何聯繫Javascript模板?

有可能嗎?

回答

0

比方說,你想使用谷歌分析您的組件上,

首先你宣佈你的index.html

... 
<script src="https://www.google-analytics.com/analytics.js"></script> 
... 

那麼你的組件(或任何的.ts文件)中,你可以訪問的JavaScript文件該javascript文件裏面的功能是這樣的:

import { Component} from '@angular/core'; 
declare const ga: any; 

@Component({...}) 
export class Component{ 
    constructor(){ 
     ga('create', "GA_ID", 'auto'); 
    } 
}