我有一個組件加載了一個基於Bootstrap.js和Jquery構建的基於H1,H2 ...標題的頁面內容表的JavaScript模塊。該組件的代碼如下:如何在加載視圖時運行SystemJs模塊
import { bindable, bindingMode, customElement, noView } from 'aurelia-framework';
@noView()
@customElement('scriptinjector')
export class ScriptInjector {
@bindable public url;
@bindable public isLocal;
@bindable public isAsync;
@bindable({ defaultBindingMode: bindingMode.oneWay }) protected scripttag;
private tagId = 'bootTOCscript';
public attached() {
if (this.url) {
this.scripttag = document.createElement('script');
if (this.isAsync) {
this.scripttag.async = true;
}
if (this.isLocal) {
System.import(this.url);
return;
} else {
this.scripttag.setAttribute('src', this.url);
}
document.body.appendChild(this.scripttag);
}
}
public detached() {
if (this.scripttag) {
this.scripttag.remove();
}
}
}
本質對於那些不熟悉Aurelia路上,這只是使用SystemJs從我的應用程序束加載自舉toc.js模塊,無論我把這個在我的觀點:
<scriptinjector url="lib/bootstrap-toc.js" is-local.bind='true'></scriptinjector>
我的問題是,雖然這工作完美,當我第一次加載視圖,後續訪問不生成目錄(目錄)。我已經檢查過,Aurelia事實上在每次加載視圖時調用System.Import,但似乎一旦一個模塊被導入一次,它就再也不會被再次導入(bundle中的代碼再也不會運行了)。
有沒有人知道我可以在重新進入視圖時卸載/重新加載/重置/重新運行模塊?