1
我們有一個SPL,其中在index.html
的ngModule這樣定義:如何加載組件動態的角度2,在不NgModule的聲明部分中列出這些
var module = ng.core.NgModule({
imports: [ng.platformBrowser.BrowserModule, ng.router.RouterModule, ng.material.MaterialModule],
declarations: [],
bootstrap: []
})
.Class({
constructor: function() { }
});
document.addEventListener('DOMContentLoaded', function() {
ng.platformBrowserDynamic
.platformBrowserDynamic()
.bootstrapModule(module);
});
正如你可以看到聲明的列表在我們的NgModule
是空的。該代碼是由例如顯影劑甲完成,並且被加載到頁旁邊index.html
在另一個地方,顯影劑B創建一個簡單的組件:
var tasks = ng.core.Component({
selector: 'tasks',
template: '<div>list of tasks here<div>'
})
.Class({
constructor: function() { }
});
該代碼被延遲加載,經由用戶的交互和路線變化。
我們該如何在模塊中包含這個組件?僞代碼可能是:
module.AddComponent(tasks);