簡體   English   中英

找不到模塊:錯誤無法解析“角度”

[英]Module not found:Error can't resolve 'angular'

我正在使用angular 6來構建網站。實際上我想在加載頁面時在元素上運行腳本。由於angular ngOnit()在加載內容之前運行腳本,所以我遇到了問題。我發現angular.element(function())可能解決了這個問題。但是當我在我的項目中安裝並將angular導入到項目中但出現錯誤時,出現的錯誤是

錯誤:找不到模塊:無法解析'../../../node_modules/@types/angular'在'C:\\ Users \\ name \\ WebProject \\ src \\ app \\ sales'中

我也將其導入到我的垂直組件中,如下所示:

從'../../../node_modules/@types/angular'中導入*作為角度;

我的內容加載后運行腳本的代碼是:

 ngOnInit() { angular.element(function () { alert('page loading completed'); }); } 

如果有人幫助我或者建議我以其他方式實現我想要的東西,那將是很棒的。 謝謝。

angular.element是AngularJS,與Angular完全不同。

ngOnInit在組件生命周期中為時過早。

嘗試像這樣使用ngAfterViewInit

ngAfterViewInit() {
  // code to run after view has initialised goes here
}

暫無
暫無

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

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