我有一个组件加载了一个基于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中的代码再也不会运行了)。
有没有人知道我可以在重新进入视图时卸载/重新加载/重置/重新运行模块?