2017-04-24 72 views
1

我仍然在學習Angular 2,所以我可能在這裏做錯了什麼。我有一個HTML/CSS模板,我試圖使其與角2.工作,我已經創建了幾個組件的Angular2項目...Angular2不會加載外部js文件當我改變視圖

在app.component.html

我有我的菜單

<ul class="clearfix"> 
 
    <li><a [routerLink]="['/']">Home</a></li> 
 
    <li><a [routerLink]="['/link1']">Link1</a></li> 
 
    <li><a [routerLink]="['/link2']">Link2</a> </li> 
 
</ul>

在i上的菜單中的一個項點擊它改變了考慮到對於i例如由組件當我點擊鏈接1它顯示我LINK1組分(link1.component.html)在視圖index.html我有

<app-root>Loading...</app-root>

,當我在菜單視圖的變化,但Angular2點擊不要加載加載index.html中它的JavaScript我已經加載的所有的CSS和JS文件,所以這個問題在這裏只那麼當我把直接鏈接。

爲了更清楚如果我把直接鏈接放在瀏覽器localhost:4200/link1腳本得到加載,我可以看到動畫或任何我已經加載在index.html中,並在link1中調用。 component.html,但如果我在家裏,並點擊菜單中的鏈接1視圖更改,但動畫或警報...不起作用。

我也不在控制檯中得到任何錯誤,並在index.html的我只加載這兩個腳本

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> 
 
<script type="text/javascript" src="/assets/js/site.min.js"></script>

+0

你能分享你的'index.html' – AngJobs

+0

@AngJobs我在下面分享 – Wissou

+0

如果你真的w螞蟻學習Angular,刪除所有的jQuery腳本,並按照[Angular Style Guide](https://angular.io/docs/ts/latest/guide/style-guide.html) –

回答

-1

您可以運行裏面的生命週期的一個jQuery的掛鉤。

不確定哪個最好 - 您需要閱讀文檔並查看哪些符合您的需求。

也許在ngAfterViewChecked之後。

https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html

export class Link1 implements ngAfterViewChecked { 
    ngAfterViewChecked() { 
     buildTree(){ 
    $('#FicheName_detailContent').height($('#NAMEsearch').height()); 
    if ($('#tvFicheName') != null) { 
     $("#t_Search").val(''); 
     var isFull = $("ck_FullOrPartiell").checked; 
     BuildTreeViewNAME($('#tvFicheName'), '', isFull, null); 
    } 
    } 
} 

(話雖這麼說 - 有一個很好的機會,你可以建立只用 角沒有jQuery的視圖)

  • 藉口formatting-棘手的在iPad上
+0

我不知道爲什麼我被降級 - 我認爲這是死亡的mot –