0
我在JavaScript(ES5)中編寫Angular 2應用程序,並且我的生命週期掛鉤未被框架調用。Angular 2生命週期掛鉤未調用(ES5 javascript)
附件包括:包含ngOnInit,index.html,app組件,app模塊,main.js的示例組件。 'all.min.js'是我用uglifyJS生成的所有Angular應用程序js文件的文件。
預期的結果是要調用該組件的ngOnInit並打印控制檯消息'ngOnInit'。 Chrome控制檯中未顯示任何消息。
index.html的(縮短爲了簡潔):
<!DOCTYPE html>
<html>
<body>
<app>Loading...</app>
<script src="/app/assets/javascript/angular/Rx.js"></script>
<script src="/app/assets/javascript/angular/core.umd.js"></script>
<script src="/app/assets/javascript/angular/common.umd.js"></script>
<script src="/app/assets/javascript/angular/compiler.umd.js"></script>
<script src="/app/assets/javascript/angular/platform-browser.umd.js"></script>
<script src="/app/assets/javascript/angular/platform-browser-dynamic.umd.js"></script>
<script src="/app/assets/javascript/angular/forms.umd.js"></script>
<script src="/app/assets/javascript/angular/shim.min.js"></script>
<script src="/app/assets/javascript/angular/Reflect.js"></script>
<script src="/app/assets/javascript/angular/zone.js"></script>
<script src="/app/assets/javascript/angular/system.js"></script>
<script src='/app/ng_app/all.min.js'></script>
</body>
</html>
app.component.js:
(function(app) {
app.AppComponent =
ng.core.Component({
selector: 'app',
template: '<brief></brief>'
})
.Class({
constructor: function() {
}
});
})(window.app || (window.app = {}));
app.module.js:
(function(app) {
app.AppModule =
ng.core.NgModule({
imports: [ng.platformBrowser.BrowserModule, ng.forms.FormsModule],
declarations: [app.AppComponent,
app.BriefComponent
],
bootstrap: [app.AppComponent]
})
.Class({
constructor: function() {}
});
})(window.app || (window.app = {}));
樣品組分(簡要組件):
(function(app) {
app.BriefComponent =
ng.core.Component({
selector: 'brief',
templateUrl: 'ng_app/brief/brief.component.html'
]
})
.Class({
constructor: function() {
},
ngOnInit: function() {
console.log('ngOnInit brief');
}
});
})(window.app || (window.app = {}));
個
main.js:
(function(app) {
document.addEventListener('DOMContentLoaded', function() {
ng.platformBrowserDynamic
.platformBrowserDynamic()
.bootstrapModule(app.AppModule);
});
})(window.app || (window.app = {}));